0

I've added a new element to the DOM and set it with ng-model attribute. Since this element didn't exist when document loaded when angular did his stuff the binding doesn't work.

How can I manually add this element to be handled with angular?

I'm sure it has been asked before but I didn't manage to find the answer...

Thanks in advance!

Gal Ziv
  • 6,890
  • 10
  • 32
  • 43

2 Answers2

1

Essentially you'd have to use $scope.$apply().

There's a fine article on this here.

EDIT:

Also, there's another question here on StackOverflow that might help. Maybe you need to use $scope.$watch() to listen for events and only then, use $scope.$apply()

Check out the question here.

Community
  • 1
  • 1
jsfrocha
  • 1,812
  • 2
  • 21
  • 32
  • i've tried $scope.$apply() as is but it doesnt work. i'll review the document for details. thanks. – Gal Ziv Nov 02 '14 at 21:00
  • The article doesn't speak on what I need. perhaps $scope.$watch() can be used as a workaround. i think what i need is $compile – Gal Ziv Nov 03 '14 at 07:20
0

after creating the element at the controller code i used

 $compile(element)($scope)

and it worked.

Gal Ziv
  • 6,890
  • 10
  • 32
  • 43