AngularJS:如何从控制器变量render指令?

时间:2014-06-19 04:26:10

标签: javascript angularjs angularjs-directive

在我的控制器中:

$scope.directiveName = 'hello-world';

我的指示:

App.directive('helloWorld',
[
function() {
  return {
    restrict: 'EAC',
    link: function(scope, ele, atr) {
      console.log('hello world from directive');
    }
  }
}]);
在我的HTML中

<div class="{{directiveName}}"></div>

为什么这不起作用?我该怎么做?

1 个答案:

答案 0 :(得分:0)

只需使用ng-bind指令将自定义指令添加到html

<div class="ng-bind:'directiveName'"></div>

Angular DOC

<强>更新 您的指令支持属性标记。所以你也可以像其他格式一样使用你的指令。

<div {{directiveName}}></div>
相关问题