define(['modules/tdpic-module', 'services/news-service', 'utilities/cryto'], function (app) {
'use strict'; app.controller('tdpic-controller', ['$scope', 'news-service', '$cookies', function ($scope, news_service, $cookies) {
$scope.name2="11";
var querytdpic=function(){
var options = {
id: 'ddece4c3-53bd-4597-b042-8852be07a739',
start: $scope.pager? $scope.pager.size * ($scope.pager.current - 1):0,
length: 10,
strSeach: $scope.strSearch?$scope.strSearch:''
};
news_service.getNews(options).success(function(res){
$scope.News = res.data;
})
}
querytdpic();
}]); });
这个错误是,我在加载依赖项时,用了其他模块的服务,注意:调用相同的服务,不同模块下的服务是不能重用的。
services/news-service该服务是定义在index-module下的服务,所以我得重新写一个在该模块下的服务,如下:
define(['modules/tdpic-module', 'app/config-server'], function (app) {
'use strict'; app.service('tdpicnews-service', ['$http', function ($http) {
var config = require('app/config-server');
var hostAddress = config.getAddress();
var dataTableheaders =
{
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" };
var newsService = {};
newsService.getNews = function (options) {
var url = 'New/GetNews';
var data = 'id=' + options.id + '&start=' + options.start + '&length=' + options.length+ '&strSearch=' + (options.strSeach ? options.strSeach : '');
return $http({url:hostAddress+url,headers:dataTableheaders,method:'POST',data: data});
}; return newsService;
}]);
});