• {{bi...">
    Geek Answers Handbook

    How to update the entire dictionary if any item has been changed?

    <body ng-controller="SomeListCtrl">
    
      <ul>
        <li ng-repeat="user in users">
          {{bindUserToImg(user.id)}}
        </li>
      </ul>
    
      <button ng-click="update()">Update img</button>
    </body>
    
    function SomeListCtrl($scope) {
      $scope.users = [
        {id: 1},
        {id: 2},
        {id: 3}
      ];
    
      $scope.images = {
        1: {src: 'img-1'},
        2: {src: 'img-2'},
        3: {src: 'img-3'}
      };
    
      $scope.bindUserToImg = function(x) {
        console.log(x);
    
        return $scope.images[x].src;    
      };
    
      $scope.update = function() {
        $scope.images[2].src = 'updated-img';    
      };
    }
    

    Code: http://jsbin.com/sanipiki/1/

    I linked users to images. Now, if some image changes (call the "update" method to change image # 2), angular will update all users (the "bindUserToImg" method will be called for each element in the "users" array). Is it possible to make angular to update only a specific image and prevent the updating of all dictionary elements?

    +4
    performance javascript angularjs
    Alexander Jul 30 '14 at 15:47
    source share
    1 answer

    , . , scope, angular , , - . /.

    angular angular "", 2. bindUserToImg , ( , ), angular .

    , , . - , , . ,

    <li ng-repeat="user in users track by $index">
      {{images[user.id].src}}
    </li>
    
    0
    Narretz 30 . '14 16:22

    More articles:

    • Get the size of a variable in Clang - c ++
    • SublimeLinter: WARNING: jshint is deactivated, cannot find "jshint" - jshint
    • Initialize the xml class obtained with Edit, Paste Special, Paste XML as classes - c #
    • parse deeply nested elasticsearch clusters using its client API - java
    • Use PowerShell to disable Taskbar shortcut depending on Target Path shortcut - windows
    • Convert language name to locale code - php
    • Language: language name for the country / language code - java
    • https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1550526/standard-function-to-translate-iso-639-codes-to-language-name&usg=ALkJrhiSA0ufxMh8AGgs4Cw94_W4MaQsFw
    • Meteor callback when a template has been re-rendered - meteor
    • How to set USER_ID in Google Universal Analytics tracking code in Rails? - ruby ​​| fooobar.com

    All Articles

    Geek Answers | 2019