我正在基于
this article在AngularJS中创建一个工厂.但是我的控制器中未定义“dataFactory”的错误.我的代码如下所示:
原文链接:https://www.f2er.com/angularjs/142938.htmlMyApp.factory('dataFactory',['$http',function($http) { var urlBase='/someurl/roles/'; var dataFactory={}; dataFactory.getRoles=function() { return $http.get(urlBase+'getlist'); }; dataFactory.addRole=function(roleName,roleCss) { return $http.get(urlBase+'add&name='+roleName+'&css='+roleCss); }; dataFactory.updateRole=function(role) { return $http.get(urlBase+edit&id='+role.id+'&name='+role.name+'&css='+role.css'); }; dataFactory.deleteRole=function(role) { return $http.get(urlBase+'remove&id='+role.id); }; return dataFactory; }]); MyApp.controller('RoleCtrl',['$scope','$http','dataFactory',function($scope,$http,$rootScope,dataFactory) { dataFactory.getRoles().then(function(res){ $scope.roles = res.data.result; }); }]);
我究竟做错了什么?