Sandeep
Sandeep

Reputation: 1479

how I get component element like link function elem variable in angular 1.5

I am new in angular 1.5 now I have a problem. How I get current component element reference in controller function like angular 1.3 link : function(scope, elem, attr) function. elem denote to directive element.

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
}

Upvotes: 1

Views: 381

Answers (1)

Eugene Hype
Eugene Hype

Reputation: 67

Try to use link function to operate on DOM and communicate with a controller via scope:

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

//watch scope changes in link function

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

Upvotes: -1

Related Questions