Vote count:
0
I have a custom directive that may or may not have an attribute with a value. If the user doesn't specify a value for the attribute, I want to assign a default. However, when I do that the value is always null on my scope, as with this Plunkr
What am I doing wrong?
Directive:
var app = angular.module('app', []);
app.directive('variable', function(){
return {
restrict: 'E',
replace: true,
template: '<h2>Directive value: {{ test }}</h2>',
scope: {
test: '@'
},
controller: function($scope){
$scope.test = 'code assignment';
}
};
});
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="http://ift.tt/NBjDXO"></script>
<script src="script.js"></script>
</head>
<body ng-app="app">
<variable></variable>
<variable test="html assignment"></variable>
</body>
</html>
asked 25 secs ago
Assigning value to scope in directive not working
Aucun commentaire:
Enregistrer un commentaire