2014-10-20 37 views
0

如果我这样做{{newStore1}}和$ scope.newStore1 ='猫头鹰商店',当页面加载时,文字说猫头鹰商店。数据绑定的一切都很好。如果我做一个输入框,并给它的模型newStoreName,那也有用,大部分...我的数据绑定工作,但我的输入NG模型没有更新时,我更新

{{newStore1}} 
<form data-ng-submit="storeUpdate()"> 
     <input type="text" ng-model="newStore1"> 
     <input type="submit" /> 
</form> 

新店名称显示为空。即使正如我在文本框中输入一样,{{newStore}}会更新文本。但是当我这样做时,它给了我一个空值。

$scope.storeUpdate = function(){ 


     Users.get({email:$scope.global.user.email}, function(user3) { 
      user3[0].store.push($scope.newStore1); // $scope.newStore1 is working in html but is 'null' here 
      user3[0].$update(function(response) { 
       Users.query({}, function(users) { 
        $scope.users = users; 
        $scope.global.user = response; 
       }); 
      }); 
     }); 
    }; 
+2

总是在'ng-model'中有一个点,所以当范围开始嵌套时你可以确保利用对象继承。基元不会在嵌套的作用域中绑定 – charlietfl 2014-10-20 04:35:12

+0

so data-ng-model =“store.name”? – 2014-10-20 04:37:48

+0

如果我在ng模型名称中加了一个点,当我点击提交时,它会显示“无法读取未定义的属性名称”。 – 2014-10-20 04:41:45

回答

0
在你的控制器

定义:

$scope.store = {};

,或者如果你不想声明它在你的控制器,在你的HTML,你需要在较高水平要声明的型号:

<div ng-model="store.name"> 
    {{store.name}} 
    <form data-ng-submit="storeUpdate()"> 
      <input type="text" ng-model="store.name"> 
      <input type="submit" /> 
    </form> 
<div> 
相关问题