0

I am creating an app in AngularJS, where I am grabbing the data from the backend to display on the view. But, for some reason, I am getting the data in my console but not in my view. I will be so thankful if any one can help me solve this. Thanks in advance.

Here is my code. -Services

    app.factory('user', ['$http', function($http) {
    var userInfo = { 
        getUserInfo: function () {
            return $http.get('https://************/*****/**/***********')
        }
    };
    return userInfo;
}]); 

home page(view)

    <div class="users" ng-repeat="user in users | filter:userSearch" >



    <a href="#/users/{{ user.id }}">
    <img ng-src="{{user.img}}"/>
    <span class="name">{{user.first}} </span>
    <span class="name">{{user.last}} </span>

   <p class="title">{{user.title}} </p>
  <span class="date">{{user.date}} </span>


</a> 

HomeController

    var isConfirmed = false;
app.controller('HomeController', function($scope, user, $http) {
    if (!isConfirmed) {
        user.getUserInfo().then(function (response) {
            $scope.userInfo = response.data;
            isConfirmed = $scope.userInfo;
            console.log($scope.userInfo);
        }, function (error) {
            console.log(error)
        });
    }
}); 

App.js

    var app = angular.module("Portal", ['ngRoute']);


    app.controller('MyCtrl', function($scope) {


    $scope.inactive = true;

        $scope.confirmedAction = function() {

        isConfirmed.splice($scope.person.id, 1);

        location.href = '#/users';

    }

}); 

index.html

    <!doctype html>
<html ng-app="Portal">
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
    <script src="https://code.angularjs.org/1.2.28/angular-route.min.js"></script>







    <link href='https://fonts.googleapis.com/css?family=Roboto:400,300,700' rel='stylesheet' type='text/css'>

    <!-- Latest compiled and minified CSS -->
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link href="css/main.css" rel="stylesheet" />



  </head>
  <body>
  <div class="header">
      <div class="container">
          <h3>Portal</h3>
      </div>
    </div>


    <div class="main">
      <div class="container">
          <div ng-view>
          </div>
      </div>
    </div>


    <!-- Modules -->
    <script src="js/app.js"></script>

    <!-- Controllers -->
    <script src="js/controllers/HomeController.js"></script>
      <script src="js/controllers/UserController.js"></script>

    <!-- Services -->
      <script src="js/services/users.js"></script>


  </body>
</html> 
3
  • Can you create a plunk for this so that we can understand what you are trying to accomplish ? I don't see anywhere in your html where a controller was defined. We'd need to see all the different pieces so a plunk will help. Commented May 17, 2017 at 15:23
  • @lacoder check updated question Commented May 17, 2017 at 17:33
  • @lacoder you got what I mean. Commented May 17, 2017 at 19:04

2 Answers 2

1

change your ng-repeat="user in users" to ng-repeat="user in userInfo" as your assigning and consoling only $scope.userInfo in your controller

Sign up to request clarification or add additional context in comments.

8 Comments

So, I have change it to 'userInfo', but I get an "Error: [filter:notarray]" type error in console.
So, I have change it to 'userInfo', but I get an "Error: [filter:notarray]" type error in console.
thats related to the filter your using in the repeat...check with removing that first....if your getting data then cross check your filter
I removed that in the console, it gets my data shown, but nothing still does not show in the view.
can you provide your consoled data so that we can work around
|
1

The property you assign data has to be same as of binded to view.

As per your HTML data should be in users. So do it like : $scope.users = response.data;.

or if you assign data to userInfo, then bind it on html. like :

 <div class="users" ng-repeat="user in userInfo | filter:userSearch" >

6 Comments

so, in my home controller I have it as '$scope.userInfo = response.data;' so instead of that use this '$scope.users = response.data;.' , right?
if yes, I am getting a undefined.
do you get data from server, in response.data ?
just print {{users}} on screen , and see if it really filled up or not ?, because it is very straight forward mechanism
no, I am not getting anything when I print out {{ users }} in my home.html.
|

Your Answer

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