4
工作,我是指导角“=”范围不与驼峰
的作用域属性,当我使用show
与attr名称,它工作正常。
<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": "="
}
};
});
(见本plunkr 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)
可能的重复[如何在AngularJS中使用属性前缀“x-”和“data-”](http://stackoverflow.com/questions/15256396/how-are-the-attribute-prefixes- x-and-data-used-in-angularjs) – Jon7
是的。我没有意识到'x-'是我问它的根本原因。 – kanitw