1.路由中定义:
.state('index.restaurant.restaurant-reports.totalPurchase', {
url: '/totalPurchase',
templateUrl: 'template/restaurantReports/totalPurchase.html',
controller: 'totalPurchaseCtrl',
resolve: {
restaurant_sales_info: function ($http, $sessionStorage) {
return $http.get(WEB_DOMAIN + '/api/Order/restaurantSalesLineChart', {
params: {
'user_id': $sessionStorage.user_info.user_id,
'year': "2017"
}
});
}
}
})
url: '/totalPurchase',
templateUrl: 'template/restaurantReports/totalPurchase.html',
controller: 'totalPurchaseCtrl',
resolve: {
restaurant_sales_info: function ($http, $sessionStorage) {
return $http.get(WEB_DOMAIN + '/api/Order/restaurantSalesLineChart', {
params: {
'user_id': $sessionStorage.user_info.user_id,
'year': "2017"
}
});
}
}
})
2.控制器中引用:
supplyAdmin.controller("totalPurchaseCtrl", ['$scope', '$http', '$stateParams', '$sessionStorage','restaurant_sales_info',
function ($scope, $http, $stateParams, $sessionStorage,restaurant_sales_info) {
$scope.legend = ['销售业绩'];
$scope.item = [];
$scope.data = [];
angular.forEach(restaurant_sales_info.data, function (data,index) {
$scope.item[index] = data.month;
$scope.data[index] = data.sales_performance;
});
$scope.data=[$scope.data]
}]);
function ($scope, $http, $stateParams, $sessionStorage,restaurant_sales_info) {
$scope.legend = ['销售业绩'];
$scope.item = [];
$scope.data = [];
angular.forEach(restaurant_sales_info.data, function (data,index) {
$scope.item[index] = data.month;
$scope.data[index] = data.sales_performance;
});
$scope.data=[$scope.data]
}]);
3.注意:对应的html页面中不能再定义ng-controller,否则会报错