你好我是angularJS新手,我嘗試在angularJS中使用onload函數。我創建了一個控制器,並在該控制器中使用$ scope.init獲取記錄形式的mysql數據庫。我正在使用laravel框架。 這是我的視圖代碼如何使用laravel框架在angular js中使用onload函數?
<div class="navbar-collapse collapse" id="navbar" ng-controller="NotificationsCtrl"> </div>
這是我的控制器代碼
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);
});
};
});
這是我的路線
Route::get('notification/getNotificationList/{user_id}', '[email protected]');
這是我laravel控制器
public function getNotification($id)
{
echo $id;
}
請幫助我,我想我犯了一個錯誤。
什麼是sessUser? –
你還在哪裏調用'$ scope.init'函數。也是爲什麼它是範圍函數?範圍函數只用於從視圖調用時使用。 –
其會話的用戶ID –