如何从控制器中的 ng-model 获取更新值
How can I get updated value from ng-model in my controller
我正在尝试从我的视图中获取更新后的值,如下所示:
<label class="item item-input">
<span class="input-label">Palabra</span>
<input style="font-size: 18px !important; text-align: right !important; font-weight: bold !important;" type="text" ng-model="addWordContent" placeholder="pa-la-bra">
</label
我把$scope.addWordContent的值初始化为NULL:
$scope.getEditPalabraRow = function($stateParams) {
Words.getEditSimple($stateParams.palabraId).then(function(single){
$scope.editWordRow = single;
$scope.addWordContent = null;
/*$scope.nodiacriso = Utilities.removeAccents($scope.editWordRow.sound_title);
$scope.mintitle = $filter('lowercase')($scope.nodiacriso);
$scope.nodiacri = Utilities.removeAccents($scope.editWordRow.title);*/
$scope.getEditLetter($scope.editWordRow);
});
因此,当用户在 html <input>
中键入新词时,我需要使用更新后的 ng-model 值,然后将其保存在我的数据库中,我正在我的控制器中尝试这样做:
Words.addWord($scope.addWordContent, $scope.imgURI, src, $scope.letter.letter_id, title);
文字是一种服务。
当我尝试保存单词时,该值仍然为 NULL,当用户填写输入文本字段时永远不会改变。问候!!
angularjs wiki 中有一篇关于作用域的文章 - https://github.com/angular/angular.js/wiki/Understanding-Scopes
我认为这可能是你的情况:
Scope inheritance is normally straightforward, and you often don't
even need to know it is happening... until you try 2-way data binding
(i.e., form elements, ng-model) to a primitive (e.g., number, string,
boolean) defined on the parent scope from inside the child scope. It
doesn't work the way most people expect it should work. What happens
is that the child scope gets its own property that hides/shadows the
parent property of the same name. This is not something AngularJS is
doing – this is how JavaScript prototypal inheritance works. New
AngularJS developers often do not realize that ng-repeat, ng-switch,
ng-view and ng-include all create new child scopes, so the problem
often shows up when these directives are involved.
我正在尝试从我的视图中获取更新后的值,如下所示:
<label class="item item-input">
<span class="input-label">Palabra</span>
<input style="font-size: 18px !important; text-align: right !important; font-weight: bold !important;" type="text" ng-model="addWordContent" placeholder="pa-la-bra">
</label
我把$scope.addWordContent的值初始化为NULL:
$scope.getEditPalabraRow = function($stateParams) {
Words.getEditSimple($stateParams.palabraId).then(function(single){
$scope.editWordRow = single;
$scope.addWordContent = null;
/*$scope.nodiacriso = Utilities.removeAccents($scope.editWordRow.sound_title);
$scope.mintitle = $filter('lowercase')($scope.nodiacriso);
$scope.nodiacri = Utilities.removeAccents($scope.editWordRow.title);*/
$scope.getEditLetter($scope.editWordRow);
});
因此,当用户在 html <input>
中键入新词时,我需要使用更新后的 ng-model 值,然后将其保存在我的数据库中,我正在我的控制器中尝试这样做:
Words.addWord($scope.addWordContent, $scope.imgURI, src, $scope.letter.letter_id, title);
文字是一种服务。
当我尝试保存单词时,该值仍然为 NULL,当用户填写输入文本字段时永远不会改变。问候!!
angularjs wiki 中有一篇关于作用域的文章 - https://github.com/angular/angular.js/wiki/Understanding-Scopes
我认为这可能是你的情况:
Scope inheritance is normally straightforward, and you often don't even need to know it is happening... until you try 2-way data binding (i.e., form elements, ng-model) to a primitive (e.g., number, string, boolean) defined on the parent scope from inside the child scope. It doesn't work the way most people expect it should work. What happens is that the child scope gets its own property that hides/shadows the parent property of the same name. This is not something AngularJS is doing – this is how JavaScript prototypal inheritance works. New AngularJS developers often do not realize that ng-repeat, ng-switch, ng-view and ng-include all create new child scopes, so the problem often shows up when these directives are involved.