Javascript 如何在控制器中获取输入的模型?

Javascript 如何在控制器中获取输入的模型?,javascript,angularjs,angular-ngmodel,Javascript,Angularjs,Angular Ngmodel,假设我有控制器和带有ngModel的输入 我想在控制器中获取此ngModel并在其上执行$setViewValue 代码段已附加。尝试执行-$setViewValue时出现错误- TypeError: Cannot set property '$setViewValue' of undefined var myAppModule=angular.module('myApp',[]); 控制器('myCtrl',函数($scope){ $scope.entityMail.$setViewVal

假设我有控制器和带有
ngModel
的输入

我想在控制器中获取此ngModel并在其上执行
$setViewValue

代码段已附加。尝试执行-
$setViewValue
时出现错误-

TypeError: Cannot set property '$setViewValue' of undefined
var myAppModule=angular.module('myApp',[]);
控制器('myCtrl',函数($scope){
$scope.entityMail.$setViewValue(“blabla@aaa.com");
});

邮寄

首先必须将$scope.entityMail声明为对象,然后只有您才能在此应用程序中应用$setViewValue

var myAppModule = angular.module('myApp', []); 
        myAppModule.controller('myCtrl',function ($scope) {
                    $scope.entityMail = {};
                    $scope.entityMail.$setViewValue("blabla@aaa.com");
        });

首先必须将$scope.entityMail声明为对象,然后只有您才能在此应用程序中应用$setViewValue

var myAppModule = angular.module('myApp', []); 
        myAppModule.controller('myCtrl',function ($scope) {
                    $scope.entityMail = {};
                    $scope.entityMail.$setViewValue("blabla@aaa.com");
        });

首先必须将$scope.entityMail声明为对象,然后只有您才能在此应用程序中应用$setViewValue

var myAppModule = angular.module('myApp', []); 
        myAppModule.controller('myCtrl',function ($scope) {
                    $scope.entityMail = {};
                    $scope.entityMail.$setViewValue("blabla@aaa.com");
        });

首先必须将$scope.entityMail声明为对象,然后只有您才能在此应用程序中应用$setViewValue

var myAppModule = angular.module('myApp', []); 
        myAppModule.controller('myCtrl',function ($scope) {
                    $scope.entityMail = {};
                    $scope.entityMail.$setViewValue("blabla@aaa.com");
        });

您可以直接将值分配给ngModel,而不是$setViewValue

$scope.entityMail  = "blabla@aaa.com";

您可以直接将值分配给ngModel,而不是$setViewValue

$scope.entityMail  = "blabla@aaa.com";

您可以直接将值分配给ngModel,而不是$setViewValue

$scope.entityMail  = "blabla@aaa.com";

您可以直接将值分配给ngModel,而不是$setViewValue

$scope.entityMail  = "blabla@aaa.com";

为什么要设置3秒的间隔
entityMail
未定义,因为它还没有任何值。请查看我的更新。即使没有值,如何更改它?为什么必须使用
$setViewValue
?只要设置值,
$scope.entityMail='something'
就会反映在视图中为什么不直接使用$scope.entityMail='blabla@aaa.com"; ?@汤姆:我只是想简化我的代码,在实际代码中,我有ngModel to指令,我必须使用setViewValue。为什么设置3秒的间隔
entityMail
未定义,因为它还没有任何值。请查看我的更新。即使没有值,如何更改它?为什么必须使用
$setViewValue
?只要设置值,
$scope.entityMail='something'
就会反映在视图中为什么不直接使用$scope.entityMail='blabla@aaa.com"; ?@汤姆:我只是想简化我的代码,在实际代码中,我有ngModel to指令,我必须使用setViewValue。为什么设置3秒的间隔
entityMail
未定义,因为它还没有任何值。请查看我的更新。即使没有值,如何更改它?为什么必须使用
$setViewValue
?只要设置值,
$scope.entityMail='something'
就会反映在视图中为什么不直接使用$scope.entityMail='blabla@aaa.com"; ?@汤姆:我只是想简化我的代码,在实际代码中,我有ngModel to指令,我必须使用setViewValue。为什么设置3秒的间隔
entityMail
未定义,因为它还没有任何值。请查看我的更新。即使没有值,如何更改它?为什么必须使用
$setViewValue
?只要设置值,
$scope.entityMail='something'
就会反映在视图中为什么不直接使用$scope.entityMail='blabla@aaa.com"; ?@汤姆:我只是想简化我的代码,在实际代码中,我有ngModel to指令,我必须使用setViewValue。