我如何在角度1.5中获得链接函数elem变量等组件元素

时间:2016-05-05 12:02:22

标签: angularjs ng-upgrade

我现在是角色1.5的新手,现在我遇到了问题。我如何获得控制器函数中的当前组件元素引用,如angular 1.3 link:function(scope,elem,attr)函数。 elem 表示指示元素。

Angular 1.3

templateUrl : "template_url",
link : function(scope, elem, attr){
    elem.find(".chips-item").append("<h1>Angular 1.3</h1>");
}

Angular 1.5

templateUrl : "template_url",
controller: function() {
    elem.find(".chips-item").append("<h1>Angular 1.3</h1>"); /// How I get current Element
}

1 个答案:

答案 0 :(得分:-1)

尝试使用链接功能来操作DOM 并通过范围与控制器通信:

//assign something to scope
scope.property = value; 

//watch scope changes in link function

scope.$watch('property', function (newVal, oldVal) { 
    /*callback on      scope changes*/
  } );