我正在使用角度服務的路由,我的服務文件是分開的。 和我面對branchService是console.See代碼未定義的錯誤Plunker code 這裏是branchService.js:未定義的服務控制器使用路由
angular.module("myApp").service('branchService', ['$http', function ($http) {
var link = "http://localhost:8008/";
//----Get Dining Tables`enter code here`
this.getBranches = function ($scope) {
return $http({
method: "GET",
url: encodeURI(link + "Branch/GetBranches/"),
headers: { 'Content-Type': 'application/json' }
}).success(function (data) {
console.log(data);
}).error(function (data) {
console.log(data);
});
};
}]);
和myController.js是在這裏:
var app = angular.module("myApp", ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider
.when('/branches', {
templateUrl: 'branches.html',
controller: 'branchController'
})
.otherwise({
redirectTo: '/branches'
});
});
app.controller('branchController', ['$scope', '$filter', 'branchService', function ($scope, $filter, branchService) {
branchService.getBranches($scope);
}
當我運行錯誤:$注射器:modulerr 模塊錯誤錯誤顯示在控制檯中
檢查Nilay科塔裏的答案。這可能只是你沒有將服務文件添加到你的index.html文件中,或者你的命名關閉了。 – groooves
檢查'錯誤:$ injector:modulerr Module Error'之前的語法錯誤消息。應用控制器需要'}])'結束。 – georgeawg
我已經在html文件中添加了所有js文件引用,並且控制檯未顯示任何語法錯誤 –