javascript - bind data with rest call in angularjs -
i have populated data rest call in webapp. want detail of particular data id. working code when refresh page. when click on button crashing webapp. here code: service.js:
(function() { angular.module('shoppingpad').service('registerservice', registerservice); function registerservice($q, $http,restservice) { var deferred = $q.defer(); //function category this.getallcategory = function () { console.log('in controller'); //calling json data return restservice.getrequest('api/category',null).then(function (response) { category = response.data; deferred.resolve(category); return deferred.promise; }, function (error) { deferred.reject(error); return deferred.promise; }); }, //function category id this.getsubcategory = function (id) { console.log('inside subcategory'); return restservice.getrequest('api/category'+'/'+id) .success(function (response) { deferred.resolve(response.data); return deferred.promise; }, function (error) { deferred.reject(error); return deferred.promise; }); }; } })();
controller.js:
(function () { angular.module('shoppingpad').controller('registerctrl', registerctrl); function registerctrl($scope, registerservice, $stateparams, $state, page) { $scope.category = null; $scope.cur_category = categoryname(categoryid); //categoryname(); var categoryid=$stateparams.categoryid; //getcategory function category rest call. $scope.getcategory = function () { //setting title registration page.settitle('registration'); registerservice.getallcategory().then(function (response) { $scope.category = response; console.log($scope.category); }); }; //passing id subcategory function sub category id $scope.subcategory = function (id) { //setting title sub-category page.settitle('sub-register'); registerservice.getsubcategory(id).then(function (data) { console.log(data); $scope.cur_category = data.data; console.log($scope.cur_category); $state.go('app.home.register3', {'categoryid': id}); }); }; //$scope.cur_category=$scope.subcategory(categoryid); $scope.signin = function () { $state.go('app.login.step1') }; } })();
registration-2.html:
<md-content > <h3 class="select-sub-category">select sub-category</h3> <div layout="row" layout="column" flex=100" style="width:200px;"> <div style="margin-left:16px" class="rectangle-425-copy-3" flex-gt-sm="50" > <span class="retail">{{cur_category}}</span> </div> </div> <div class="path-625"></div> <div flex layout="row" layout-align="center" layout-wrap> <div class="rectangle" flex="120" flex-md="90" flex-sm="95" layout="row" layout-wrap> <div flex="45" class="rectangle-4251" ng-repeat="cat in cur_category.details"> <span class="electronics" >{{cat}}</span> </div> </div> </div> <div class="terms-conditions"> <span>terms & conditions</span> </div> <md-toolbar class="rectangle-4091" style="background-color: #9013fe; "> <div class="md-toolbar-tools"> <md-button class="submit" aria-label="settings"> <a ui-sref="app.home.register4"><span style="margin-left: 100px;" >proceed</span></a> </md-button> </div> </md-toolbar> </md-content>
registration-1.html:
<md-content > <h3 class="select-category">select category</h3> <div ></div> <div flex layout="row" layout-align="center" layout-wrap> <div class="rectangle" flex="120" flex-md="90" flex-sm="95" layout="row" layout-wrap ng-init="getcategory()"> <div flex="45" class="rectangle-425" ng-repeat="cat in category"> <span ng-click="subcategory(cat.id)"class="automotive">{{cat.name}}</span> <md-icon class="ic_add_black_24px" md-svg-src="{{cat.icon}}"></md-icon> </div> </div> <!-- <div ui-view></div> --> </div> <div class="terms-conditions"> <span>terms & conditions</span> </div> </md-content>
app.js:
$stateprovider.state('app.home.register2', { url: "/register", templateurl: 'template/register/registration-1.html', controller: 'registerctrl', onenter: function () { console.log('in ap.regi2'); } }) .state('app.home.register3', { url: "/register/{categoryid:[0-9]{1,5}}", templateurl: 'template/register/registration-2.html', controller: 'registerctrl', onenter: function () { console.log('in ap.regi3'); } })
Comments
Post a Comment