search

Home  >  Q&A  >  body text

angular.js - 有人看过Angular即学即用这本书吗

代码如图,书本上说,ng-repeat可作用于对象,作用于对象的话HTML渲染出来的结果会使大写字母开头的Misko排在前面,书上说的代码结果是Misko、brad、shyma。但我打出来的代码结果却是按照我写的顺序shyma、Misko、brad。求解答是我代码打错了还是书上有误?我链接的Angular是v1.5.0,书上说它采用的是1.2.19

<body ng-controller="MainCtrl as ctrl">
    <p ng-repeat="(author,note) in  ctrl.notes">
        <span class="label">{{note.label}}</span>
        <span class="author" ng-bind="author"></span>
    </p>
    <script src="../js/angular.min.js"></script>
    <script type="text/javascript">
        angular.module('notesApp',[]).controller('MainCtrl',[
            function(){
                var self=this;
                self.notes={
                    shyam: {
                        id:1,
                        label:'First Note',
                        done:false
                    },
                    Misko: {
                        id:3,
                        label:'Finished Third Note',
                        done:true
                    },
                    brad: {
                        id:2,
                        label:'Second Note',
                        done:false
                    }
                };
            }]);
    </script>
</body>
習慣沉默習慣沉默2745 days ago566

reply all(1)I'll reply

  • 阿神

    阿神2017-05-15 17:04:43

    Version1.4.0The above is cycled out according to the order in which these attributes (shyma, Misko, brad) are in the object (notes).


    Supplement: Different versions display different results

    The results displayed in

    1. Version 1.5.6 are as follows:

    are displayed in the order of shyma, Misko, and brad.

    2. The results displayed in version 1.2.0 are as follows:

    are displayed in the order of Misko, brad, and shyma.

    reply
    0
  • Cancelreply