The code I have tried is :
html code(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);
}
}])
This is part of my ionic code.Names is an array of objects with property name and selected.so when a user types in a name it gives suggesstions.when you click suggestions the selected property of object is changed to true.What is expected then is to see a list of selected object name at the bottom but it does not show.
Can anyone help?
I think it is a spelling mistake
<li ng-repeat="name in names | filter:query" ng-show="(!name.setected&&query)">
it should be ng-show="(!name.selected&&query)"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.