@Ckpk wrote:
Hello Mastah,
Where is wrong with below code? I can get the JSON result directly through any browser, it just don't want to show up in the dropdown list
I am just trying to populate from mysql database to combobox in ionic framework.
addlist.html
<ion-header-bar align-title="center" class="bar-stable"> <h1 class="title">Add Lists</h1> </ion-header-bar> <ion-view> <div class="list has-header padding"> <label class="item item-input item-select"> <div class="input-label"> Category </div> <div ng-controller="AddListCategoryCtrl"> <select ng-model="category" ng-options="x.category for x in data"> <option ng-repeat="x in data" value="{{x.id}}">{{x.category}}</option> </select> </div> </label> </div> </ion-view>
controllers.js
angular.module('ionicApp.controllers', []) .controller('AddListCategoryCtrl', function($scope, $http) { var xhr = $http({ method: 'post', url: 'http://www.mywebsite.com/api/listCat.php' }); xhr.success(function(data){ $scope.data = data.data; }); });
listCat.php
<?php include 'db.php'; getById(); function getById() { $sql = "SELECT id,category FROM tbl_category ORDER BY tbl_category.id"; try { $db = getDB(); $stmt = $db->prepare($sql); $stmt->execute(); $category = $stmt->fetchAll(PDO::FETCH_OBJ); $db = null; echo '{"category": ' . json_encode($category) . '}'; } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } } ?>
Posts: 15
Participants: 3