Reputation: 6242
I am new in Angular.js and want to know more about it. I just created a small project And want to pass multiple value with $scope object. But it's not working properly.
Here what I am doing
function ListCtrl($scope, $http,Project) {
$http.get('/project').success(function(data){
str =data.result;
var result= str.replace('http://','domainname');
$scope.projects=data.rows;
$scope.projects=data.result;
});
}
In data variable I am getting rows and result. And I am passing something like above with $scope.
Any help will be appreciated.
Upvotes: 0
Views: 1893
Reputation: 5865
Your problem is, that the view is not informed about the changes of the $scope.data
variable, due to the fact that the value is changed in the async callback of the Promise
which is returned by the $http.get()
method.
Just wrap your $scope
changes in a $scope.$apply
method to run the digest loop:
$http.get('/project').success(function(data){
$scope.$apply(function() {
// Do scope changes here
})
}
Additionally you are assigning the value $scope.projects
twice, so change this:
$scope.projects = {};
$scope.projects.rows = data.rows;
$scope.projects.results = data.result;
or just:
$scope.projects = data;
Upvotes: 1
Reputation: 8346
Try this,
$scope.projects = {};
$scope.projects.rows = data.rows;
$scope.projects.result = data.result;
Upvotes: 1
Reputation: 433
These two will overwrite each other.
$scope.projects=data.rows;
$scope.projects=data.result;
What you want to do might be more like this.
$scope.projects = {};
$scope.projects.rows = data.rows;
$scope.projects.result = data.result;
Then in your html if you want to display these, you can use ng-repeat to iterate over them and display each element. Do you have HTML to go with this that you are using?
Upvotes: 0