考虑我有控制器并输入ngModel
。
我想在控制器中获取此ngModel并对其执行$setViewValue
。
该代码段已附加。尝试执行-$setViewValue
给出错误-
TypeError: Cannot set property '$setViewValue' of undefined
var myAppModule = angular.module('myApp', []);
myAppModule.controller('myCtrl',function ($scope) {
$scope.entityMail.$setViewValue("[email protected]");
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<div ng-app="myApp">
<form ng-controller="myCtrl">
Mail <input type="text" ng-model="entityMail">
</form>
</div>
如何正确获取此ngModel并对其执行
$setViewValue
?编辑:
我编辑了代码。我必须将其与
$setViewValue
一起使用。 最佳答案
var myAppModule = angular.module('myApp', []);
myAppModule.controller('myCtrl',function ($scope,$interval) {
$scope.entityMail = "[email protected]";
});