AngularJS: late-binding of ng-model to dom element
You need to use $compile
(docs)
$compile(myModel2.attr("ng-model", "myModel2"))($scope);
When you load your page, angular uses $compile
on the HTML automatically, that's how it knows which elements to assign which directives to. If you just change the attribute like you tried, angular doesn't know. You have to use $compile
.