ng-bind-html数据+变量正确的语法

时间:2016-01-25 11:28:33

标签: angularjs

我找不到办法运行这个东西...... 我正在使用ng-bind-html从db加载文本。我想将一个变量添加到几种语言中的一种。但我不明白正确的语法。 我想用这样的东西:

<div ng-bind-html="detail.txt+lang"></div>

其中lang是一个rootScope变量(“_ en”,“_ it”等) 感谢

1 个答案:

答案 0 :(得分:0)

我会这样做:

//inside the controller for the view
$scope.writeValueFromDb = function() {
    //here you can access the $rootScope
    //(after including it as a dependency in the controller)
    //and from the $rootScope object you can access the language variable
}

执行此操作,您不必在视图中绑定的每个方法中手动传递$rootScope中的语言变量。

在视图中,您可以正常绑定它:

<div ng-bind-html="writeValueFromDb()"></div>