ReferenceError:未定义$ state [英] ReferenceError: $state is not defined
本文介绍了ReferenceError:未定义$ state的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用AngularJS的Rails应用程序,但我遇到了一个问题,问题是提交表单后,我想重定向到某个 state
,但是在chrome的控制台中,我有一个 ReferenceError:未定义$ state
,什么也没发生.
I have a rails application which use AngularJS and I have a problem, the problem is that I want redirect to a certain state
after a form is submited, but in the chrome's console I have a ReferenceError: $state is not defined
and nothing happens.
这是我的控制器.
angular.module('myapp')
.controller('CreatePollCtrl', ['$scope', 'Restangular', '$state',
function($scope, Restangular) {
$scope.addPoll = function() {
if ($scope.allow_anonymous_answer == null)
$scope.allow_anonymous_answer = false
var poll = {title: $scope.title, description: $scope.description, allow_anonymous_answer: $scope.allow_anonymous_answer, initial_message: $scope.initial_message, final_message: $scope.final_message};
Restangular.all('polls').post(poll).then(function(response) {
$state.go('dashboard');
});
};
}]);
我该怎么办? $ state
是否已正确注入?
What can I do?, is $state
correctly injected?
推荐答案
您忘记将 $ state
添加到 function()
angular.module('myapp')
.controller('CreatePollCtrl', ['$scope', 'Restangular', '$state',
function($scope, Restangular, $state) {
这篇关于ReferenceError:未定义$ state的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文