Я новичок в AngularJS. Я создал приложение с AngularJS. У меня есть папка приложения, внутри которой у меня есть папка списка с файлом: List.html и
listcontroller.js
angSalaryApp.controller('listController',
function ListController($scope, ListService) {
$scope.list = listService.newlist;
$scope.count = 0;
$scope.submitForm() = function () {
};
$scope.updateName() = function () {
$scope.count++;
};
});
listService.js
angSalaryApp.factory('ListService',
["$http",
function ($http) {
var newList = function(){
return $http.get("Areas/Employer/List/newlist");
};
}
]);
listdirective.js
angSalaryApp.directive("listForm", function () {
return {
restrict: "E",
templateUrl: "app/list/list.html"
}
});
В папке приложения у меня есть JS файл как SalaryApp.js
var angSalaryApp = angular.module('angSalaryApp',[])
Когда мой код вызывал $ http.get, я получил сообщение об ошибке
Error: [$injector:undef] Provider 'ListService' must return a value from $get factory method.
http://errors.angularjs.org/1.4.6/$injector/undef?p0=ListService
at enforcedReturnValue (http://localhost:5137/Scripts/angular.js:4330:9)
at invoke (http://localhost:5137/Scripts/angular.js:4476:7)
at Anonymous function (http://localhost:5137/Scripts/angular.js:4293:13)
at getService (http://localhost:5137/Scripts/angular.js:4435:11)
at invoke (http://localhost:5137/Scripts/angular.js:4464:9)
at Anonymous function (http://localhost:5137/Scripts/angular.js:9127:11)
at nodeLinkFn (http://localhost:5137/Scripts/angular.js:8239:13)
at compositeLinkFn (http://localhost:5137/Scripts/angular.js:7671:13)
at compositeLinkFn (http://localhost:5137/Scripts/angular.js:7675:13)
at publicLinkFn (http://localhost:5137/Scripts/angular.js:7546:30)
В контроллере вы ListService
поэтому вызывайте ListService.newlist
вместо listService.newlist
angSalaryApp.controller('listController',
function ListController($scope, ListService) {
$scope.list = ListService.newlist;
});
На фабрике он должен возвращать object
но вы не возвращаете какой-либо object
поэтому возвращаете объект, добавляя функцию в объект возврата.
angSalaryApp.factory('ListService', ["$http",
function($http) {
return {
newList: newList
};
function newList() {
return $http.get("Areas/Employer/List/newlist");
}
}
]);