1

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.

3 Answers 3

1

Try this,

$scope.projects = {};

$scope.projects.rows = data.rows;
$scope.projects.result = data.result;
Sign up to request clarification or add additional context in comments.

Comments

1

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;

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.