Here is the HTML and Javascript for a simple Angular JS example. In this example, why didn't the link function run and set scope.flag
to be true
(boolean) instead of 'true'
(string)?
Javascript:
angular.module('truthyTypes', [])
.directive('myDirective', function(){
return {
template: '<div>flag value: {{ flag }}<br/>flag type: {{ flag | typeOf }}</div>',
scope: {
flag: '@'
},
link: function(scope){
scope.flag = scope.flag === 'true';
}
}
})
.filter('typeOf', function(){
return function(input){
return typeof input;
}
})
;
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example78-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.1/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="truthyTypes">
<div my-directive flag="true"></div>
</body>
</html>
Live Example: http://plnkr.co/edit/jqk5529FmdGsxK6Xj8LZ?p=preview