你好我是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 –