我是指令的范围属性
我使用时效果很好show
作为属性名称。
<span ng-repeat="field in fields">
<field-pill field="field" show="true"></field-pill>
</span>
app.js
angular.module('app',[]);
angular.module('app')
.controller('AppCtrl', function($scope){
$scope.fields = [1,2,3,4];
});
angular.module('app')
.directive('fieldPill', function () {
return {
template: '<div class="pill">{{field}}:{{show}}--<span ng-show="show">x</span></div>',
restrict: 'E',
scope:{
field: "=",
"show": "="
}
};
});
(看这个笨蛋http://plnkr.co/edit/AcqmxeCerCOtGaw9dq9t?p=preview http://plnkr.co/edit/AcqmxeCerCOtGaw9dq9t?p=preview)
但是当我使用时该指令根本不加载布尔数据x-show
作为属性名称。
<span ng-repeat="field in fields">
<field-pill field="field" x-show="true"></field-pill>
</span>
app.js
angular.module('app',[]);
angular.module('app')
.controller('AppCtrl', function($scope){
$scope.fields = [1,2,3,4];
});
angular.module('app')
.directive('fieldPill', function () {
return {
template: '<div class="pill">{{field}}:{{xShow}}--<span ng-show="xShow">x</span></div>',
restrict: 'E',
scope:{
field: "=",
xShow: "="
}
};
});
谁能解释为什么?
(请参阅此 plunkr 的代码x-show
http://plnkr.co/edit/2txoY3VaShH6WggnugcE?p=preview http://plnkr.co/edit/2txoY3VaShH6WggnugcE?p=preview )