binding scope property with a dash in html template

后端 未结 2 1667
被撕碎了的回忆
被撕碎了的回忆 2021-01-28 05:37

For some reason, I have to use dash in property like test-name and cannot use testName or testname:

angular.module(\'testA         


        
相关标签:
2条回答
  • 2021-01-28 06:12

    Try this, it should work:

    <div ng-controller="TestController">
      This is {{this['test-name']}}
    </div>
    
    0 讨论(0)
  • 2021-01-28 06:20

    That is because when {{test-name}} is parsed by $parseProvider and Lexer in angular, the - is recoginzed as an minus operator.

    https://github.com/angular/angular.js/blob/master/src/ng/parse.js#L1005

    {{this['test-name']}} should work

    0 讨论(0)
提交回复
热议问题