最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ReferenceError: $state is not defined - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Jan 26, 2016 at 19:29 Patricio SPatricio S 2,1303 gold badges24 silver badges52 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

you forgot add $state to function()

angular.module('myapp')

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

Add $state as a parameter to your function, like $scope.addPoll = function($state) {...}

发布评论

评论列表(0)

  1. 暂无评论