角" = QUOT;范围不与驼峰工作 [英] Angular "=" scope does not work with camelCase
问题描述
我是一个指令的作用域属性。
I'm scope property of a directive
当我使用显示
与attr的名称,它工作正常。
It works fine when I use show
as attr name.
<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展
作为属性名称。
But the directive doesn't load the boolean data at all when I use x-show
as the attribute name.
<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: "="
}
};
});
任何人能解释为什么吗?
Can anyone explain why?
(请参阅本plunkr为code。与 X展
的 http://plnkr.co/edit/2txoY3VaShH6WggnugcE?p=$p$pview )
(See this plunkr for the code with x-show
http://plnkr.co/edit/2txoY3VaShH6WggnugcE?p=preview )
推荐答案
我认为这是与该 X -
preFIX。如果您将其更改为类似的东西 mShow
, M-节目
,它会工作。
I think it is relating to the x-
prefix. If you change it to anything like mShow
, m-show
, it will work.
从HTML5 规范:
属性名与这两个字符开头的X-被保留
用户代理使用,并保证永远不会被正式加入到
HTML语言。为了提高灵活性,属性包含姓名
下划线(在U + 005F低线字符)也被保留
实验的目的,并保证永远不会被正式加入到
HTML语言。
Attribute names beginning with the two characters "x-" are reserved for user agent use and are guaranteed to never be formally added to the HTML language. For flexibility, attributes names containing underscores (the U+005F LOW LINE character) are also reserved for experimental purposes and are guaranteed to never be formally added to the HTML language.
因此要避免使用 X -
正常属性名。 :)
So avoid using x-
for normal attribute name. :)
这篇关于角&QUOT; = QUOT;范围不与驼峰工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!