You are trying to read the set value before Angular is done assigning.
app.controller("EventOfCategoryController", function($scope, $http, $filter) {
$timeout(function(){
console.log($scope.categoryId);
},1000);
$http.get('/category/'+$scope.categoryId).success(function(data, status, headers, config) {
// my functions
});
});
Ideally you should use $watch as bellow if you need to use ng-init at all:
app.controller("EventOfCategoryController", function($scope, $http, $filter) {
console.log('test');
$scope.$watch("categoryId", function(){
console.log($scope.categoryId);
$http.get('/category/'+$scope.categoryId).success(function(data, status, headers, config) {
// my functions
});
});
});
You can also use a method in you ng-init as follows. This will reduce watch load and increase performance.
app.controller("EventOfCategoryController", function($scope, $http, $filter) {
console.log('test');
$scope.init = function(categoryId){
console.log(categoryId);
$http.get('/category/'+categoryId).success(function(data, status, headers, config) {
// my functions
});
});
});
And ng-int as
<input type="hidden" ng-init="init(<%=id%>)" />