[英]Why the angularjs one-way bind function run twice?
I have a modal view: 我有一个模态视图:
<ion-content id="friendContent" class="scroll-content has-header has-subheader" style="background-color: rgba(0, 0, 0, 0.6);">
<ion-list class="list">
<ion-item ng-repeat="objFriendInfo in objFriendInfoList | filter:{ Remark: data.searchQuery }" class="item item-avatar-left item-button-right searchFriendItemBackgroundColor"
ng-click="FriendList('chat',objFriendInfo,$event)">
<img class="imgFriendUser" ng-class="{ 'gray':objFriendInfo.state == 0 }" ng-src="{{::objFriendInfo.icon }}">
<h2 class="light">{{::GetAndSaveFriendName('friendlist_UserName',objFriendInfo.Remark,'16px', objFriendInfo) }}</h2>
<h3 class="positive" ng-click="FriendList('travellog',objFriendInfo,$event)">{{::GetAndSaveFriendTravellogName('friendlist_TravellogName',objFriendInfo.TravelLog_Name,'14px', objFriendInfo) }}</h3>
<div class="buttons" style="top:15px !important;">
<button class="center button button-small button-positive ion-edit" ng-if="objFriendInfo.id != user.id" style="font-size:16px;" ng-click="FriendList('remark',objFriendInfo,$event)"></button>
<button class="center button button-small button-positive icon-mapsay_delete" ng-if="objFriendInfo.id != user.id" style="font-size:25px;" ng-click="FriendList('delete',objFriendInfo,$event)"></button>
</div>
</ion-item>
</ion-list>
</ion-content>
and the function GetAndSaveFriendName code is: 函数GetAndSaveFriendName的代码是:
$scope.GetAndSaveFriendName = function (name, text, fontSize, objFriendInfor) {
var strDisplayName = "";
console.log(text);
if (objFriendInfor.strDisplayName) {
strDisplayName = objFriendInfor.strDisplayName;
} else {
strDisplayName = ServiceForChatCommon.GetShowDivText(name, text, fontSize);
objFriendInfor.strDisplayName = strDisplayName;
}
return strDisplayName;
};
The problem is the function GetAndSaveFriendName will run twice, what's the reason? 问题是函数GetAndSaveFriendName将运行两次,这是什么原因?
[EDIT] [编辑]
I decalre the controller like: 我给控制器贴花像:
.config([
'$stateProvider',
function ($stateProvider) {
$stateProvider
.state('tabs.chat', {
url: '/chat',
views: {
'chatView': {
templateUrl: 'components/chat-component/chat-view.html',
controller: 'chatController'
}
}
})
}]);
I think I found the reason. 我想我找到了原因。 The $digest of AngularJs run at least twice, the second recyle make sure the DOM is the up-to-date. $ digest的AngularJs至少运行两次,第二步确保DOM是最新的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.