本文介绍了在html模板中使用破折号绑定范围属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出于某种原因,我必须在 test-name
等属性中使用破折号,并且不能使用 testName
或 testname
:
For some reason, I have to use dash in property like test-name
and cannot use testName
or testname
:
angular.module('testApp')
.controller('TestController',function($scope){
//neither 'testname' nor 'testName', only 'test-name'
$scope['test-name'] = 'Test name...';
});
现在我想在html模板中绑定它:
And now I want to bind it in the html template:
<div ng-controller="TestController">
This is {{test-name}}
</div>
我也试过 {{testname}}
和 {{testName}}
但不起作用。
I've also tried {{testname}}
and {{testName}}
but doesn't work.
有没有办法它?
目前产生的结果如下:
This is 0
但预期结果如下:
This is Test name...
推荐答案
试试这个,它应该有效:
Try this, it should work:
<div ng-controller="TestController">
This is {{this['test-name']}}
</div>
这篇关于在html模板中使用破折号绑定范围属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!