简体   繁体   中英

ReferenceError: $state is not defined

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.

状态错误

This is my controller.

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');
    });
  };
}]);

What can I do?, is $state correctly injected?

you forgot add $state to function()

angular.module('myapp')

.controller('CreatePollCtrl', ['$scope', 'Restangular', '$state',
function($scope, Restangular, $state) {

$state作为参数添加到函数中,例如$scope.addPoll = function($state) {...}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM