角" = QUOT;范围不与驼峰工作 [英] Angular "=" scope does not work with camelCase

查看:166
本文介绍了角" = QUOT;范围不与驼峰工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个指令的作用域属性。

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆