【发布时间】:2016-09-02 08:47:39
【问题描述】:
我正在尝试从控制器调用工厂函数。
我的代码:
angular.module("mainApp", ['ui.router', 'ngAnimate', 'toaster'])
.factory("authenticationSvc", function($http, $q, $window) {
var userInfo;
function login(userName, password) {
var deferred = $q.defer();
$http.post("/api/login", {
userName: userName,
password: password
}).then(function(result) {
userInfo = {
accessToken: result.data.access_token,
userName: result.data.userName
};
$window.sessionStorage["userInfo"] = JSON.stringify(userInfo);
deferred.resolve(userInfo);
}, function(error) {
deferred.reject(error);
});
return deferred.promise;
}
return {
login: login
};
})
.controller("LoginController", function($scope, toaster, $rootScope, $stateParams, $location, $http, authenticationSvc) {
$scope.login = authenticationSvc.login();
});
但我收到一个错误
TypeError: authenticationSvc.login 不是函数
【问题讨论】:
-
你设置断点到 $scope.login = ...? das authenticationSvc 有什么价值?
标签: angularjs controller factory