SolarTerms.controller('FooterCtrl', ['$state', '$rootScope', '$scope', function ($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",function () {
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') }) } } })
Homepage
Balance
Calculate
Documentation
Get the index after clicking the corresponding p, and then change the corresponding value in $scope.imgsrc. The console can correctly output the image address, but why does the value in ng-src in the view need to be clicked twice to change? I just want to Change the image address in ng-src. I just started learning angularjs. Can someone explain it to me? Thank you.
You need to manually trigger angular’s rendering mechanism