cari

Rumah  >  Soal Jawab  >  teks badan

angular.js - Isu kemas kini nilai dalam paparan dalam angularjs

SolarTerms.controller('FooterCtrl', ['$state', '$rootScope', '$skop', fungsi ($state, $rootScope, $scope) {

$scope.imgsrc = {
    "imda1":"img/icon1.png",
    "imda2":"img/icon2.png",
    "imda3":"img/icon3.png",
    "imda4":"img/icon4.png",
    "imda5":"img/icon5.png"
}

}])

SolarTerms.directive("tabImg",fungsi () {

    return {
        restrict:'A',
        scope:false,
        link:function (scope,ele,attr,ctrl) {
            ele.bind('click',function (event) {
                var index = $(this).index();
                scope.imgsrc = {
                    "imda1":"img/icon1.png",
                    "imda2":"img/icon2.png",
                    "imda3":"img/icon3.png",
                    "imda4":"img/icon4.png",
                    "imda5":"img/icon5.png"
                };
                scope.imgsrc['imda'+(index+1)] = 'img/icon'+(index+1)+'1.png';
                //scope.$apply(scope.imgsrc['imda'+(index+1)] = 'img/icon'+(index+1)+'1.png')
            })
        }
    }
})

<p tab-img class="I_AF_p" ng-click="goto('index')"><img ng-src="{{imgsrc.imda1}}" alt="">< span>Homepage</span></p>
<p tab-img class="I_AF_p" ng-click="goto('ye')"><img ng-src="{{imgsrc . imda2}}" alt=""><span>balance</span></p>
<p tab-img class="I_AF_p" ng-click="goto('js')" > <img ng-src="{{imgsrc.imda3}}" alt=""><span>Hitung</span></p>
<p tab-img class="I_AF_p " ng- click="goto('ck')"><img ng-src="{{imgsrc.imda4}}" alt=""><span>Lihat</span></ p>
< ;p tab-img class="I_AF_p" ng-click="goto('wd')"><img ng-src="{{imgsrc.imda5}}" alt=""> Dokumen</span></p>

Dapatkan indeks selepas mengklik p yang sepadan, dan kemudian tukar nilai yang sepadan dalam $scope.imgsrc Konsol boleh mengeluarkan alamat imej dengan betul, tetapi mengapa nilai dalam ng-src dalam paparan perlu diklik dua kali untuk menukar. ? Saya hanya mahu menukar alamat imej dalam src Saya baru mula belajar angularjs.

PHP中文网PHP中文网2744 hari yang lalu678

membalas semua(1)saya akan balas

  • PHP中文网

    PHP中文网2017-05-16 13:20:53

    Anda perlu mencetuskan mekanisme pemaparan sudut secara manual

     link:function (scope,ele,attr,ctrl, $timeout) {
                ele.bind('click',function (event) {
                    var index = $(this).index();
                    scope.imgsrc = {
                        "imda1":"img/icon1.png",
                        "imda2":"img/icon2.png",
                        "imda3":"img/icon3.png",
                        "imda4":"img/icon4.png",
                        "imda5":"img/icon5.png"
                    };
                    
                    $timeout(function() {
                        scope.imgsrc['imda'+(index+1)] = 'img/icon'+(index+1)+'1.png';
                        //scope.$apply(scope.imgsrc['imda'+(index+1)] = 'img/icon'+(index+1)+'1.png')
                    })
                    
                })
            }

    balas
    0
  • Batalbalas