ng-show没有按预期工作

时间:2015-05-25 11:45:18

标签: javascript angularjs oop ionic-framework ionic

我尝试的代码是:

html代码(updata.html)

<form role="form" ng-submit="submit()">
<input type="text" ng-model="query" >
      <div class="item item-input item-stacked-label item-divider">
      <li ng-repeat="name in names | filter:query" ng-show="(!name.selected&&query)">
      <button type="button" ng-click="name.selected=true; addname(name)">{{name.name}}</button>
    </li>

      </div>
      <li ng-repeat="name in names" ng-show="name.selected">{{name.name}}</li>
 <div class="padding">
      <button type="submit" class="button button-block button-positive">Submit</button>
    </div>
</form>

angular js code

 angular.module('starter', ['ionic','ngCordova','ngRoute'])
.run(function($ionicPlatform) {
 $ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the   accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
  cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}
});
})
.config(['$routeProvider',function($routeProvider) {
 $routeProvider.when(
 '/',{
  templateUrl: 'main.html',
  controller: 'datactr'
}
)
.when(
'/indata',{
  templateUrl:'updata.html',
  controller:'datactr'
})
.when(
'/outdata',{
  templateUrl:'outdata.html',
  controller:'datactr'
})
.otherwise({
redirectTo:'/'
})
}])
.controller('datactr',['$scope','$http',function($scope,$http) {
$scope.submit=function(){
          console.log("step1");

    $http({
      method:'POST',
      url:'http://awesomeg.2fh.co/updata.php',
      crossDomain : true,
      data:{
         'name':$scope.namefinal
          }
      }).success(function(data,status,header,config){
      console.log("step2");
      console.log(data);
      $scope.namefinal="";
      $scope.message="You have successfully updated the database";
    })
    $scope.names=[{'name' :'harry',
'selected':false},{'name' :'george',
'selected':false}];
$scope.namefinal=[];
$scope.addname=function(test){
$scope.namefinal.push(test.name);
}     
}])

这是我的离子代码的一部分.Names是一个具有属性名称和selected的对象数组。当用户输入名称时,它会给出suggesstions。当你点击建议时,对象的selected属性会变为true。然后是在底部看到所选对象名称的列表,但它没有显示。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:4)

我认为这是一个拼写错误

<li ng-repeat="name in names | filter:query" ng-show="(!name.setected&&query)">

应为ng-show="(!name.selected&&query)"