What causes the one-way bind function in angularjs to execute twice?

I am currently working on a modal view that includes:

<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>

As for the function GetAndSaveFriendName code snippet:

$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;
            };

An issue has arisen where the function GetAndSaveFriendName is being executed twice, but I'm unsure why. Any insights?

[EDIT]

The controller declaration looks like this:

.config([
        '$stateProvider',
        function ($stateProvider) {
            $stateProvider
                .state('tabs.chat', {
                    url: '/chat',
                    views: {
                        'chatView': {
                            templateUrl: 'components/chat-component/chat-view.html',
                            controller: 'chatController'
                        }
                    }
                })
        }]);

Answer №1

After some investigation, I have discovered the issue. It seems that AngularJs's $digest function runs multiple times to ensure that the DOM remains current and updated.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When a React Router link is activated, the React Bootstrap dropdown remains open instead of closing as expected

<NavDropdown className="userDropdownButton" title="dropdown" id="user-nav-dropdown" alignRight > <div className="userDropDown"> <Link to="/user" className="userDropDownheader"> user </Link> </div> < ...

Is it possible for me to perform cross-site scripting using JavaScript within my personal browser, specifically Firefox?

While watching a Video Tutorial on a certain website, I noticed that the videos were hosted on platform.thinkific.com and displayed in a light theme. However, I prefer Dark Theme, so I decided to invert the color of the video using the filter: invert(90%) ...

Controller unable to update AngularJS view

As the title suggests... I'm facing a challenge with this code snippet: (function(angular) { 'use strict'; angular.module('app', []) .controller('ctrl', ['$scope', function($scope) { $scope.ini ...

Looking for a simple method to convert JSON object properties into an array?

Is there a simple method for extracting only the values of the properties within the results object in the given JSON data? let jsonData = {"success":true, "msg":["Clutch successfully updated."], "results":{"count_id":2, ...

Display Rails view using JavaScript when clicked

I have a task to create a view where users can click on different buttons and see different content displayed based on the button they choose. I attempted to achieve this using JavaScript, but unfortunately, I couldn't get it to work as intended. Init ...

What is the best way to synchronize a function within the array.forEach loop that uses asynchronous

Suppose I have an array and I need to apply an asynchronous function to each element of the array. let arr = [item1, item2, item3] // My goal is to await arr.forEach(async (item) => {...}) // This can be achieved by let asyncFunc = async (item) => ...

Unexpected token error in TypeScript: Syntax mistake spotted in code

Being new to Angular, I understand that mastering TypeScript is crucial for becoming a skilled Angular developer. Therefore, I created this simple program: function loge(messag){ console.log(messag); } var message:string; message = "Hi"; loge(messa ...

Why do confirm or alert boxes in Safari on Windows require a double click?

I'm currently working on a simple JavaScript example where I want to display an alert box when an HTML button is clicked in SAFARI. However, I've noticed that it requires a double click to make the alert disappear from the screen. Does anyone ha ...

Encountering Challenges with Implementing the Range Datepicker jQuery Plugin

While working on a website project, I encountered an issue when trying to implement a range date picker form. The error message that kept appearing was: Uncaught TypeError: Cannot read property 'firstChild' of null" Despite my efforts and ext ...

Discovering when the DOM has finished rendering in AngularJS with ng-repeat

I am looking for a way to trigger an alert or message upon completion of rendering in my HTML DOM using AngularJS, specifically when dealing with multiple ng-repeats. HTML Code: <body> <div ng-controller="Ctrl"> <div ng-repeat= ...

The Bootstrap slide function encounters issues within the AJAX success callback

Here's the code snippet with a 'slide' event inside an AJAX success call. success: function(data) { $('#my_container').html(data); // Successfully loading #mycarousel into #my_container $('#mycarousel').bind( ...

I encountered some problems with conflicting Angular dependencies, so I decided to delete the node_modules folder

An error has occurred: The module 'H:\All_Files\Scripts\Angular\example\node_modules\source-map\source-map.js' could not be found. Please ensure that the package.json file contains a correct "main" entry. ...

Adding a characteristic to every item in an array of objects

Currently, I am utilizing Node.js along with Mongoose to interact with a MongoDB database and retrieve an array of objects from a specific collection. However, my aim is to add an additional property to each of these retrieved objects. Below, you can see t ...

Utilize the `document.getElementById` method to trigger both function 2 and form 2 when clicked

Hey there, I'm having some issues with my code and would appreciate some help. After a user submits my form with the ID of 'fwrdform' using the onclick event, I want to also trigger another function from my 'logout-form' so that t ...

Implement admin-on-rest framework within my current project

Currently, I am in the process of building an admin-tool website using Material UI. To handle asynchronous calls, I have integrated Redux Saga into my project for calling services. The Admin on Rest framework offers some beneficial components like the Data ...

Is it possible to have a never-ending slideshow with inline-blocks?

After spending countless hours trying to troubleshoot my code, I am now seeking help from the wonderful people of the internet! ;) It seems like only a small portion of my code is incorrect. What I'm attempting to do is move the leftmost object in the ...

Validating emails using jQuery Ajax technology

I'm facing an issue with a simple form where users are required to input their email address. My Ajax script is designed to verify this email against the database and validate its existence. The validation seems to be working, but I'm struggling ...

Determining the clicked node in a JavaScript environment

There are multiple spans with labels. <span class="viewEdit">View and edit class one.</span> <span class="viewEdit">View and edit class two.</span> <span class="viewEdit">View and edit class three.</span> <span clas ...

Navigating from the online realm to leisure activities

As a web developer with knowledge in PHP, Python, Ruby, and JavaScript, I've tackled various web projects but now I have a strong desire to dive into game development. It may seem like a big leap, but I'm determined to learn and explore this new ...

Importing JSON Data into an HTML File

I need to load a JSON file containing HTML content into my main HTML file upon clicking a button. ABC.json includes: <li><img src="images/picture6.jpg" /></li> <li><img src="images/picture5.jpg" /></li> <li><i ...