我有一个指令:
var myApp = angular.module('myApp', []);
var HelloDirective = function() {
return {
scope: {
list: "=",
showValue: "="
}, // use a new isolated scope
restrict: 'AE',
replace: false,
template: '<h3>List value is {{list}}</h3><br/>Raw value is [{{showValue}}] <br/><br/>showValue value is: <span ng-show="showValue">True</span><span ng-hide="showValue">False</span>'
};
}
myApp.directive("helloDirective", HelloDirective);
myApp.controller('MyCtrl', function($scope) {
$scope.name = 'Angular Directive';
$scope.osList = "Original value";
$scope.bv = true;
})
这是我的HTML:
<div ng-controller="MyCtrl">
Hello, {{name}}! Value is {{bv}}
<p list="osList" showValue="bv" class="" hello-directive></p>
</div>
这是输出:
你好,Angular Directive!价值是真的
列表值为原始值
原始值为[]
showValue值为:False
oList正确显示,但showValue没有正确传递布尔值,有什么问题?看到这个小提琴:
答案 0 :(得分:2)
它(属性)应该是show-value="bv"
而不是showValue="bv"
答案 1 :(得分:2)
您应该在camelCase
(连字符分隔的情况)中使用属性名称。
在映射到隔离范围属性时,指令规范化过程将使其showValue="bv"
处理。
show-value="bv"
应该是
{{1}}