“Duplicates in a repeater are not allowed” on ng-repeat

前端 未结 6 1980
野的像风
野的像风 2021-02-05 06:48

I\'ve got the following json data returned from a service request:

{
    \"entries\": [{
        \"id\": 2081,
        \"name\": \"BM\",
        \"niceName\": \"         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 07:22

    If I may add an additional reason as to why this can occur...

    If you are doing this with a JS object [] or {}

    and you are passing it in to a directive like this

    
    

    Inside the directive you must turn myObject back into an object by doing this

    ...
    controller: function( $scope ){
    
      $scope.links = $scope.$eval( $scope.myObject );
    ....
    

    Then the HTML and ng-repeat will work

    ...
    
    ...
    

    ngRepeat does not know how to repeat over a single string.

    Here is what the object would look like before $scope.$eval

    "[{ hello: 'you' }]"
    

    and after $scope.$eval()

    [{ hello: 'you' }] an actual object to repeat over.
    

    The error kind of makes a reference that it cannot repeat of a string. Here is the error that I got.

    Error: [ngRepeat:dupes] http://errors.angularjs.org/1.3.0-beta.8/ngRepeat/dupes?p0=link%20in%20links&p1=string%3Al

提交回复
热议问题