1

I am new to anglarJs and have the following angular js controller with this fixed data

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

        $scope.sortType = 'name'; //Setting the default sort type
        $scope.sortReverse = false; // Setting the deafult sort order
        $scope.searchDefaultTerm = ''; //Setting the default search/filter term

        $scope.users = 
     [
         {
             "id":1,
             "firstName":"Axil",
             "lastName":"Creations",
             "email":"[email protected]",
             "image":"http://localhost:8000/backend/libraries/Filemanager-master/userfiles/UserImages/user.png",
             "status":1,
             "userRole":13,
             "roleTitle":"Admin"
         }
     ];


});

this is my view

   <tr data-ng-repeat="user in users">
        <th>@{{ user.id }}</th>
        <th>@{{ user.firstName }}</th>
        <th>@{{ user.lastName }}</th>
        <th>@{{ user.email }}</th>
        <th>@{{ user.image }}</th>
        <th>@{{ user.status }}</th>
        <th>@{{ user.roleTitle }}</th>
    </tr>

everything is working fine but as soon as I send the same data via php I get error Below is my angular js controller code when I send data from php, the member variable is set in the php's controller where I have used JeffreyWay PHP-Vars-To-Js-Transformer to assign the data to javascript memeber variable although the member variable and my fixed data look same still I am having problems I have provided the screenshots to show the data are same.

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

            $scope.sortType = 'name'; //Setting the default sort type
            $scope.sortReverse = false; // Setting the deafult sort order
            $scope.searchDefaultTerm = ''; //Setting the default search/filter term

            $scope.users = members;
});

Left-When data is sent from php -  Right- Fixed Data

I have done <tr data-ng-repeat="user in users track by $index"> but now I am not receiving my data and I am getting a hude number of empty rows as shown below enter image description here

2
  • I have provided the screenshot of the data I am receiving in both case with left being the data sent via php and right being the fixed they are both same I think I am having problem with the the ng-repeat have a look at the data i.e the users @jbigman Commented May 18, 2015 at 11:07
  • ho, yeah did not see, because of tiny screenshots ^^ Commented May 18, 2015 at 11:15

4 Answers 4

1

The solution is to read the error message you have received :

You have a link describing your error :

http://errors.angularjs.org/1.3.15/ngRepeat/dupes?p0=user%20in%20users&p1=string%3A%22&p2=%22

So, if you want to fix it, you have to do the following :

<tr data-ng-repeat="user in users track by $index">
Sign up to request clarification or add additional context in comments.

1 Comment

I did so but still I am not getting my values for say @{{ user.id }} the errors gone but all I am getting now is lot of empty columns
0

Found What the problem was PHP's associative array becomes an object literal in JavaScript so using JavaScript's JSON.parse method parses the obtained JSON string and returns the JavaScript equivalent so this is all I had to do $scope.users = JSON.parse(members);

Comments

0

From link in the error you provided :

Occurs if there are duplicate keys in an ngRepeat expression. To resolve this error either ensure that the items in the collection have unique identity or use the track by syntax to specify how to track the association between models and DOM.

So, if php service send duplicates, try this:

<tr data-ng-repeat="user in users track by $index">

warning The sreenshots shows that you only have one element in the array ? The error is probably somewhere else because there is obviously no duplicates.

6 Comments

I did so but still I am not getting my values for say @{{ user.id }} the errors gone but all I am getting now is lot of empty columns
Are you sure "members" have the exact same format as the fixed json ? Try to display the json in the html {{users}} to see what $scope.users contains.
that is what I have done in my screenshot also what I did was console.log my json data that was sent via php then I used the same data as fixed data and it works@jbigman
The only way to have different behaviours is different data. Console log is extracted from $scope.users value ?
thanks for your help you were right different behaviours due to problem in my data @jbigman
|
0

Remove '@' in your code and try it out.

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.