angularjs state.go不工作

时间:2016-02-16 10:40:56

标签: angularjs angularjs-routing

我正在尝试在删除请求成功时加载表单,如下所示

 $scope.delete = function (id) {

        if (confirm("Are you sure you want to delete this record?")) {

        var url = 'http://localhost/AwtCW2012002/api/restApiController/question.json/'+id;

        $http({
                  method: 'DELETE',
                  url: url,
                  })
            .success(function() {

                $state.go(app.addEditQuestion);

                 })

我在控制器中注入了状态

angular.module('app', []).controller('questionEditCtrl', ['$state','$scope', '$http', function ($state,$scope, $http) {

我得到的错误是

Error: [$injector:unpr] http://errors.angularjs.org/1.5.0-rc.0/$injector/unpr?p0=%24stateProvider%20%3C-%20%24state%20%3C-%20questionEditCtrl
    at Error (native)
    at http://localhost/AwtCW2012002/assets/js/angular.min.js:6:421
    at http://localhost/AwtCW2012002/assets/js/angular.min.js:42:203
    at Object.d [as get] (http://localhost/AwtCW2012002/assets/js/angular.min.js:40:175)
    at http://localhost/AwtCW2012002/assets/js/angular.min.js:42:265
    at d (http://localhost/AwtCW2012002/assets/js/angular.min.js:40:175)
    at Object.e [as invoke] (http://localhost/AwtCW2012002/assets/js/angular.min.js:40:445)
    at L.instance (http://localhost/AwtCW2012002/assets/js/angular.min.js:84:168)
    at v (http://localhost/AwtCW2012002/assets/js/angular.min.js:63:446)
    at g (http://localhost/AwtCW2012002/assets/js/angular.min.js:56:341)(anonymous function) @ angular.min.js:111(anonymous function) @ angular.min.js:84m.$apply @ angular.min.js:138(anonymous function) @ angular.min.js:20e @ angular.min.js:40c @ angular.min.js:19zc @ angular.min.js:20be @ angular.min.js:19(anonymous function) @ angular.min.js:303j @ jquery-1.11.3.min.js:2k.fireWith @ jquery-1.11.3.min.js:2m.extend.ready @ jquery-1.11.3.min.js:2J @ jquery-1.11.3.min.js:2
gridView:77 GET http://localhost/AwtCW2012002/views/Images/BackgroundImage.jpg 404 (Not Found)

app.js

var app = angular.module('app', ['ui.router', 'ngTable', 'ngRoute', 'ngResource', 'ui.bootstrap', 'questionAddCtrl', 'questionEditCtrl']);

app.config(['$stateProvider', '$urlRouterProvider', '$routeProvider', '$locationProvider', function ($stateProvider, $urlRouteProvider, $routeProvider, $locationProvider) {

1 个答案:

答案 0 :(得分:0)

此错误表示您的依赖项注入存在问题。

来自doc

  

此错误是由于$ injector无法解析所需的依赖项而导致的。要解决此问题,请确保依赖关系已定义并拼写正确

您应该像这样配置状态提供程序:

angular.module('app', []).config(function($stateProvider) {
    // state handling goes here
});

有关更多信息,请参阅this