【发布时间】:2016-04-24 17:11:58
【问题描述】:
您好,我是 angularJS 的新手,我尝试在 angularJS 中使用 onload 函数。我创建了一个控制器,并在该控制器中使用 $scope.init 从 mysql 数据库中获取记录。我正在使用 laravel 框架。 这是我的视图代码
<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}', 'ProjectController@getNotification');
这是我的 laravel 控制器
public function getNotification($id)
{
echo $id;
}
请帮助我,我认为我犯了一个错误。
【问题讨论】:
-
还有你在哪里调用
$scope.init函数。还有为什么它是作用域函数?作用域函数只能在视图调用时使用。