2017-06-02 18 views
0

私は自分のルートで.stateを解決しました。ここで私はconsole.logを.stateルートに置いたときに定義されるリスト(サーバからのデータ)を返しますが、コントローラではそれはconsole.logです。私はイオン1とAngularJSを使っています。

ルートコントローラで未定義の解決プロパティ

.state('app', { 
    url: '/app', 
    abstract: true, 
    templateUrl: 'templates/menu.html', 
    controller: 'AppCtrl', 
    controllerAs: 'appcn', 
    resolve: { 
    notificationsResolve: function ($http) { 
     $http.defaults.headers.common.Authorization = "Basic MzEwMzIzOjEyMw=="; 
     return $http.get("http://192.168.178.24:8090/notifications/") 
       .then(function (response) { 
       return response.data; 
       }); 
    } 
    } 
}) 

コントローラ

angular.module( 'starter.controllers'、[ 'appServiceAPI'])

.controller('AppCtrl', ['notificationService', function($ionicModal, $timeout, notificationsResolve, 
                 notificationService) { 

    var vm = this; 

    console.log("resolve: " + notificationsResolve); 

    vm.notifications = notificationsResolve; 

答えて

2
.controller('AppCtrl', ['notificationService', 
       function($ionicModal, $timeout, notificationsResolve, notificationService) { 

あなたが3を忘れてしまいましたあなたの4つの議論のうちアレイ。それは

.controller('AppCtrl', ['$ionicModal', '$timeout', 'notificationsResolve', 'notificationService', 
       function($ionicModal, $timeout, notificationsResolve, notificationService) { 

かそれ以上である必要があり、あなただけのこの醜いとバグが発生しやすい繰り返しなしで、基本的な構文を使用し、あなたのためにあなたのコードのminifiableを作るためにng-annotateを使用する必要があります。

+1

と一致する必要があります...これは問題であり、このタスクを実行するためのプラグインを使用するのではなく1000倍を、それをめちゃくちゃにして毎回混乱しているオフはるかに良いです。 – shaunhusain

+0

ありがとう!両方の答えは正しいですが、私はこれを受け入れたものとしてマークします – Merv

0

のparams、それらの名前は、まさにこの

// this is wrong 
.controller('AppCtrl', 
    ['notificationService', 
    function($ionicModal, $timeout, notificationsResolve, notificationService) 

// this correct 
.controller('AppCtrl', 
    ['$ionicModal', '$timeout', 'notificationsResolve', 'notificationService', 
    function($ionicModal, $timeout, notificationsResolve, notificationService) 
関連する問題