如何从控制器中的ng-model获取更新值

时间:2015-12-12 00:27:38

标签: angularjs cordova ionic-framework ngcordova

我正试图从我的视图中获取更新的值:

<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

我在NULL中初始化$ scope.addWordContent的值:

$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时,当用户填充输入文本字段时,永远不会更改。问候!!

1 个答案:

答案 0 :(得分:1)

有一篇关于angularjs wiki中范围的文章 - https://github.com/angular/angular.js/wiki/Understanding-Scopes

我认为这可能是你的情况:

  

范围继承通常很简单,而且通常不会   甚至需要知道它正在发生......直到你尝试双向数据绑定   (即表格元素,ng-模型)到基元(例如,数字,字符串,   boolean)在子范围内从父范围定义。它   不像大多数人期望的那样工作。怎么了   是孩子范围得到自己的隐藏/阴影的属性   同名的父属性。这不是AngularJS的内容   做 - 这就是JavaScript原型继承的工作原理。新   AngularJS开发人员通常没有意识到ng-repeat,ng-switch,   ng-view和ng-include都创建了新的子范围,所以问题就出现了   经常出现在涉及这些指令的时候。