2016-04-24 4 views
0

こんにちは、私はangularJSで新しく、私はangularJSでonload関数を使用しようとしています。私は1つのコントローラを作成し、$ scope.initを使用してそのコントローラにフェッチレコードフォームmysqlデータベースを作成しました。私はlaravelフレームワークを使用しています。 これは、これは)私のコントローラコードlaravelフレームワークで角度jでonload関数を使用するにはどうすればいいですか?

app.controller('NotificationsCtrl', function($scope, $http, $window, $timeout){ 

var user_id = sessUser.user_id; 
alert(user_id); 
$scope.init = function() 
{ 
    $scope.getNotificationList(); 
}; 

$scope.getNotificationList = function() 
    { 
    $scope.dataLoading = true; 
    $http.get(siteUrl+"notification/getNotificationList/"+user_id).then(function(response) 
    { 
     alert(response); 
    }); 
    };  

}である私のビューコード

<div class="navbar-collapse collapse" id="navbar" ng-controller="NotificationsCtrl"> </div> 

あります。

これは

Route::get('notification/getNotificationList/{user_id}', '[email protected]'); 

私のルートであるこれは私がミスをしたと思う、私を助けてください、私のlaravelコントローラ

public function getNotification($id) 
{ 
    echo $id; 
} 

です。あなたがここにあなたのマークアップの 'NG-INIT' ディレクティブを使用することができます

+0

sessUserとは何ですか? –

+0

また '$ scope.init'関数を呼び出しています。なぜスコープ関数なのでしょうか?スコープ関数は、ビューからのみ呼び出すときに使用するためのものです。 –

+0

セッションのユーザーID –

答えて

0
$scope.init = function() 
{ 
    $scope.getNotificationList(); 
}; 

$scope.init(); 
0

あなたはthis.Youがあなたのinit method.Alsoビューで使用しない限り、スコープ機能を記述する必要はありませんを呼び出していないようなあなたのコントローラーを作成する必要があります。

app.controller('NotificationsCtrl', function($scope, $http, $window, $timeout){ 

var user_id = sessUser.user_id; 
alert(user_id); 
var getNotificationList = function() 
{ 
    $scope.dataLoading = true; 
    $http.get(siteUrl+"notification/getNotificationList/"+user_id).then(function(response) 
    { 
     alert(response); 
    }); 
};  

var init = function() 
{ 
    getNotificationList(); 
}; 

init(); //call here init 
} 
+0

このページの応答を表示するとき[オブジェクトオブジェクト] –

+0

Console.log実際の結果を表示するための応答 –

+0

コードを与えようとしましたが、ロード後のページの再配置がオブジェクトオブジェクト –

関連する問題