在html模板中使用破折号绑定范围属性 [英] binding scope property with a dash in html template

查看:320
本文介绍了在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}} 但不起作用。 保持 $ scope ['test-name']

I've also tried {{testname}} and {{testName}} but doesn't work. keeping $scope['test-name']

有没有办法它?

目前产生的结果如下:

This is 0

但预期结果如下:

This is Test name...


推荐答案

试试这个,它应该有效:

Try this, it should work:

<div ng-controller="TestController">
  This is {{this['test-name']}}
</div>

这篇关于在html模板中使用破折号绑定范围属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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