Here is the code snippet that I have been working on:
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 specific segment of my Ionic code involves an array of objects called "names" with properties like name and selected. As a user types in a name, suggestions are provided. When a suggestion is clicked, the selected property of the corresponding object should change to true. The expected outcome is to see a list of selected object names at the bottom, but it doesn't display as intended.
I am seeking assistance from anyone who can help troubleshoot this. Thank you!