angularjs – 无法注入$location服务

前端之家收集整理的这篇文章主要介绍了angularjs – 无法注入$location服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这段代码给了我错误:[$injector:unpr]未知提供者:$scope,$locationProvider< - $scope,$location.

var app = angular.module('myApp.controllers',[]);

app.controller('Signup',['$scope,$location',function($scope,$location) {
    $scope.checkEmailValid = function(){
        //TODO make a decision about whether to go somewhere,if true do this:
        $location.path('/view2');
    };
}]);

我错过了有关如何注入位置服务的内容吗?
我没有配置$locationProvider,但这样做似乎没有帮助.

解决方法

你忘记了$scope和$location附近的报价:

var app = angular.module('myApp.controllers',['$scope','$location',if true do this:
        $location.path('/view2');
    };
}]);

这应该是诀窍!

猜你在找的Angularjs相关文章