0

Is it possible to bind a model to an html node which is added by jQuery? I tried:

 $('mydiv').append('<input ng-model="myValue" type ="text" ); 

what does not work. Model is not binded.

1
  • I'd rather advise you to drop jQuery manipulation with Angularjs, it's MVC the View should be driven by Controller Commented Jul 31, 2014 at 10:01

1 Answer 1

1

You need to use compile the new element

//assuming $scope refer to the scope to which it has to be binded
var $el = $('<input ng-model="myValue" type ="text" />').appendTo('mydiv')
$compile($el)($scope);

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.