Angularjs $routeProvider template function and parameter doubts

Source: Internet
Author: User

In the ANGULARJS official documentation about the configuration of $routeprovider, there is a phrase for template and Templateurl configuration

If it is a function, it'll be called with the following Parameters:{array.<object>}-route parameters extracted F Rom the Current$location.path () by applying the current route

It is not easy to understand what it means to read it quite a mouthful.

In a nutshell, the value of the template and Temlateurl can be a function that takes parameters and returns a URL for an HTML script and an HTML script file, respectively. The case with no parameters is simple, and the corresponding data can be returned. What about the parameters, and what are the parameters? The above mentioned is the route parameters (route parameter). At first, I thought it was $routeparams, so we took $routeparams as a parameter. In fact, when defining a function, the arguments we pass are actually formal parameters. Where does the argument come from? This function is actually executed in the background and is passed by Angularjs to the function, and of course we need to set the parameters in the function in order to reference the arguments. How did the argument come from? The $location.path () of the current route is mentioned above. In the path configuration fragment, it is mentioned that if the path parameter is used with a named group (named Group), its parameters are extracted and stored in $routeparams. The parameter that is extracted in path is our argument here.

Look at the code:

<! doctype html>

After execution, you can output {"Test": "1"} in the console.

The scope of the problem ($scope. URL) is also shown earlier in this section. And the application of global function re-angularjs.

This article is from the "formeforyou" blog, make sure to keep this source http://tancfeng.blog.51cto.com/4079342/1727699

Angularjs $routeProvider template function and parameter doubts

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.