簡體   English   中英

單擊類別列表時,我需要獲取產品

[英]I need to get products when I clicked on the category list

我正在為此應用程序使用Intelxdk。 這是一個移動應用程序。

單擊該類別后,我的類別列表將顯示,我必須重定向產品頁面,當我單擊該類別時,我會得到一些類似的錯誤。 “找不到變量:$ state”。

CategoryController.js

app.controller('CategoryController', ['$scope','getServices','JSONDataService', function($scope,getServices,JSONDataService) {

    var url = 'http://look4what.biz/mobile/shop-category.php';

    $scope.getId = function(termid){ 
        JSONDataService.addTansferData(termid);
        $state.go('/:id');
    }

    getServices.sendRequest(url)
        .success(function(data, status, headers, config) {
            $scope.userslists = data;

         }).error(function(data, status, headers, config) {

         });

    }]);

app.js

var app = angular.module('LookApp', ['ionic','ngCordova','ngRoute','paymentCtrls']);  

    app.config(function($stateProvider, $urlRouterProvider,$routeProvider) {
        $routeProvider 
            .when('/', {
                 controller: 'CategoryController',
                 templateUrl: 'views/category.html'
             })
             .when('/:id', {
                 controller: 'ProductController',
                 templateUrl: 'views/users.html'
             })
             .when('/login/:friendId', {
                  controller: 'LoginController',
                  templateUrl: 'views/login.html'
             })
             .otherwise({
                 redirectTo: '/'
             });
         });

ProductController.js

app.controller('ProductController', ['$scope', '$routeParams', 'category','JSONDataService','getServices', function($scope, $routeParams, category,JSONDataService,getServices) {

    $scope.newData = JSONDataService.getTansferData();

    term_id="+$scope.newData;

    var url = "http://look4what.biz/mobile/id-get-detail.php?term_id="+termid;

    getServices.sendRequest(url)
        .success(function(data, status, headers, config) {
            $scope.userslists = data;

         })
        .error(function(data, status, headers, config) {

         });

    }]);

如果要使用$ state -Service,則需要先注入它:

app.controller('CategoryController', ['$scope','$state','getServices','JSONDataService', function($scope, $state, getServices, JSONDataService) {

    var url = 'http://look4what.biz/mobile/shop-category.php';

    $scope.getId = function(termid){ 
        JSONDataService.addTansferData(termid);
        $state.go('/', { id : termid});
    }
    ...
}

這是關於將$ state作為控制器的服務注入的小例子:

var app = angular.module('app', ['ui.router']);

app.controller('ctrl', function ($scope, $state) {
  $scope.changeState = function () {
    $state.go('contact.detail');
  };
});

並詳細說明:

http://angular-ui.github.io/ui-router/site/#/api/ui.router.state。$ state

angularJS中的狀態提供者和路由提供者

您的代碼與$ stateProvider:

app.config(function($stateProvider, $urlRouterProvider) {

    $urlRouterProvider.otherwise('/');

    $stateProvider
        .state('home', {
             url:'/'
             controller: 'CategoryController',
             templateUrl: 'views/category.html'
         })
         .state('id', {
              url:'/:id'
             controller: 'ProductController',
             templateUrl: 'views/users.html'
         })
         .state('login.friendId', {
              url:'/login/:friendId'
              controller: 'LoginController',
              templateUrl: 'views/login.html'
         })

     });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM