Angular. bind usage experience, angularngbindhtml

Source: Internet
Author: User

Angular. bind usage experience, angularngbindhtml

Angular. bind

Explanation: return a function fn that calls self (self represents this In fn). The args (*) parameter can be provided to fn. this function is also called a local operation to differentiate functions.

Format: angular. bind (self, fn, args );

Self: object; fn context object, which can be called using this In fn

Fn: function; binding method

Args: Input fn Parameters

  var obj = { name: "Any" };  var fn = function (Adj) {    console.log(this.name + "is a boy!!! And he is " + Adj + " !!!");  };  var f = angular.bind(obj, fn, "handsome");  f();//Any is a boy!!! And he is handsome!!!  var t = angular.bind(obj, fn);  t("ugly");// Any is a boy!!! And he is ugly!!!

Let's talk about angular. bind ~

As the name implies, bind is bound. If we want to bind A to B, there must be two other entities, A and B. The two objects required here are an object and a function. So how to bind it? @ The understanding of the beast is to "bind" the object to this function for execution. At this time, this of fn is equal to obj. As for the third parameter, this parameter is optional, if the function needs to input parameters, we can set angular. put the third parameter of bind, which is the input parameter of the fn function.

In this case, the first method is to pass the parameters required by fn when defining the binding, and use them directly when calling the function. In this case, the second method is to bind the function first, when the call is executed, the fn parameter is passed again, and the effect is the same.

For the above English sentence (well, although there are only two sentences), if something is wrong, it means that we love our native language-Chinese. If you accidentally write it right, so please applaud the installation of 66666 B ~

At the end of the article, let's look at an example.

<! Doctype html> 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.