当我点击类别列表时,我需要获取产品
I need to get products when I clicked on the category list
我正在为这个应用程序使用 Intelxdk。这是一个移动应用程序。
我的类别列表将显示,单击该类别后,我必须重定向产品页面,当我单击类别时,我可能会收到这样的错误。"找不到变量:$state"。
类别控制器.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) {
});
}]);
应用.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: '/'
});
});
产品控制器.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注入作为控制器服务的小示例:
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'
})
});
如果你想使用$state服务,你需要先注入它:
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});
}
...
}
相关文章:
- 如何在jquery中获取列表项的最顶端父项的文本
- 根据列表元素的值使用JQuery获取列表元素
- 正在获取列表项位置()
- 如何在委托中获取列表项中元素的内部HTML
- 用javascript从mysql中获取列表变量
- 在 jQuery 的自动完成中获取列表项单击的名称
- Jquery - 如何获取列表项中的元素
- 在 django 中获取列表值
- 在 Vista Gadget 中使用 Javascript 获取列表数据
- 使用 SPServices 从另一个域上的 SharePoint 获取列表项总数
- jQuery:如何获取列表元素的索引
- 获取列表项中当前 ID 的值
- 获取列表项的值并发布到 ajax
- 获取列表中的第一个 DOM 元素
- 获取列表项的文本内容
- 如何在javascript中获取列表中td的值
- $ionicLoading在从Ionic中的Firebase获取列表期间未显示
- Iscroll-Jquery-获取列表项的位置
- 从自动填充的JSON列表中获取列表选项值,并传递给JS函数
- 如何获取列表项'JSON加载的未排序列表中的s id