2016-11-26 5 views
0

にデータを渡すカント..私はちょうどに何かを渡すカント私のコントローラUI-ルータ(解決)が、私はこのようなコードを実行したときに、私のコントローラは動作を停止し、それがAPIまたは他の方法からの決意と渡されたデータのすべての種類、で発生コントローラ

> $urlRouterProvider.otherwise('/movies') 
>     $stateProvider 
>       .state('movies', { 
>         url: '/movies', 
>         templateUrl: 'templates/movies.html', 
>         controller: 'indexCtrl', 
>         resolve: { 
>           resolveParam: function(){ 
>             return 'sdsadasdasd' 
>             } 
>         } 
>       }) 
> 
>   }]); 
> 
> 
>   app.controller('indexCtrl', ['$scope', 'resolveParam',    function($scope, resolveParam) { 
>    $scope.click = function() { 
>       alert(); 
> 
> 
> 
>     } 
>   }]); 

がいる限り、私はこのようにそれを実行すると、それは完全に正常に動作しますが、タイプミスがある可能性があります

+0

約束する。その後、 – user2085143

+0

それはこの http://pokit.org/get/img/9968e3ce68f6d8e13d7b4c35c66a5b9b.jpgのように作業する必要がありますが、それは – Kerim092

+0

をdoesntのスタックトレース上の誤差はありますか? – vistajess

答えて

0

私の状態はまだ上記のように同じように見えても
app.controller('indexCtrl', ['$scope', function($scope) { 
      $scope.click = function() { 
        alert(); 
      } 
    }]); 

..またはいくつかの他のh ard-to-traceエラーです。 JSfiddleはあなたのコードに基づいて正常に動作しています。

http://jsfiddle.net/vcx171qa/

JS

angular.module('app', ['ui.router']) 
    .config(['$urlRouterProvider', '$stateProvider', function($urlRouterProvider, $stateProvider) { 
    $urlRouterProvider.otherwise('/movies') 
    $stateProvider 
     .state('movies', { 
     url: '/movies', 
     template: '<div>{{resolveParam}}</div>', 
     controller: 'indexCtrl', 
     resolve: { 
      resolveParam: function() { 
      return 'sdsadasdasd'; 
      } 
     } 
     }) 

    }]) 

.controller('indexCtrl', ['$scope', 'resolveParam', function indexCtrl($scope, resolveParam) { 
    $scope.resolveParam = resolveParam; 
}]); 

HTML

<html> 
    <head> 
     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.9/angular.js"></script> 
     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.2/angular-ui-router.js"></script> 
    </head> 
    <body ng-app="app" class="ng-scope"> 
     <ui-view></ui-view> 
    </body> 
</html> 

出力

あなたの決意を返す必要がありenter image description here

+0

で動作しています。おそらく、私はコントローラのメソッド内でHTTPリクエストを行ったので、それを把握する時間がありませんでした..とにかくおかげでみんな – Kerim092

関連する問題