0

Given:

<input ng-model="prop1"> 

How can I change the target of ng-model from 'prop1' to 'prop2'? The following changes the attribute value in the DOM but the directive does not react to that.

angular.element('input').attr('ng-model', 'prop2');

I can recompile the element and then it works:

angular.element('input').attr('ng-model', 'prop2');
$compile(angular.element('input'))($scope);

But that leaks watches, I can tell using Batarang's Performance tab.

What is the right way of doing this?

4

1 回答 1

0

使用中间值来存储两者

<input ng-model="prop">

$scope.prop = prop1

然后稍后

$scope.prop = prop2
于 2013-06-14T05:14:05.410 回答