【发布时间】:2015-04-27 07:23:54
【问题描述】:
我有customers.php 文件,它产生json 数据。当我们像这样更改 url 中的变量时,json 数据列表正在更改
customers.php?var=5
在 AngularJS 中,我制作了包含两个单独部分的 html 文件。第一部分是具有特定值的选择选项。第二部分是显示 json 数据的部分。很明显,第二部分使用 $http.get(url),其中 url 是控制器中的 customers.php?var=selected_number。
当用户在 ... select > html 文件中选择特定选项时,如何更改使用 $http.get 的控制器中的 url。
脚注:这是控制器文件的示例
var Pajsije = angular.module('CodeOverflow', ['ngRoute']);
Pajsije.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/viewa', {
templateUrl : 'viewa.html',
controller : 'ViewAController'
})
// route for the about page
.when('/viewb', {
templateUrl : 'viewb.html',
controller : 'ViewBController'
})
// route for the contact page
.when('/viewc', {
templateUrl : 'viewc.html',
controller : 'ViewCController'
})
.otherwise({
redirectTo: '/viewa'
});
});
// create the controller and inject Angular's $scope
Pajsije.controller('ViewAController', function($scope) {
// create a message to display in our view
$scope.message = 'Good look!';
});
Pajsije.controller('ViewBController', function($scope) {
$scope.message = 'Look about page.';
});
Pajsije.controller('ViewCController', ['$scope','$http', '$templateCache', function($scope, $http, $templateCache) {
$scope.myChange = function() {
$http({method: 'GET', url: '../json-data/customers.php?idstudm=12', cache: $templateCache}).success(function (response) {$scope.names = response.records;});
};
}]);
【问题讨论】:
-
是否选择也在
ViewCController控制器中? -
是的,确实如此。选择选项在 ViewCController 中。
标签: javascript php json angularjs