Angularjs route-Pass value $routeparams

Source: Internet
Author: User

The ANGULARJS uses route-passing values,

1. Guide Package

<src= "Angular.min.js"></script>    <  src= "Angular-route.js"></script>

2. Dependency Injection Ngroute

var myapp=angular.module ("MyApp", ["Ngroute"]);

3. Configure Routing

myapp.config (function ($routeProvider) {//page selection $routeProvider. When ("/home", {//T Emplate: "<H2>This is the main page.</H2>"Templateurl:" home.html "}). When ("/about", {//Template: "<H2>This is a message about us.</H2>"Templateurl:" about.html "}). When ("/cel", {//Template: "<H2>Please contact us</H2>"Templateurl:" cel.html ",//Controller:" Celctrl "}). When ("/cel/:sub", {//Parameter templateurl: "Cel.html", Controller: "Celctrl"})}) ;

4. Write CEL's controller

Myapp.controller ("Celctrl", Function ($scope, $routeParams) {            //assigns a value to the input box according to the passed parameter           var param = $routeParams ["Sub" ];           if (param== "a") {               $scope. mname= "I'd like to make a suggestion ...";           } else if (param== "B") {               $scope. mname= "I want to Buy ..."}        );

5. Send value to cel page via about page

<P>About page</P>    <ul>        <Li><ahref= "#cel /A">Tell us</a></Li>        <Li><ahref= "#cel/b">Inquiry</a></Li>    </ul>

Modify the value of the input box for the CEL page

<P>Show Page</P>    <ul>        <Li><inputtype= "text"placeholder= "Sub"Ng-model= "Mname"></Li>        <Li><inputtype= "text"placeholder= "Message"Ng-model= "Minfo"></Li>    </ul>

Finally, the page layout

<BodyNg-app= "MyApp"><!--Page Layout -    <Header>        <P>My Site</P>        <Div>            <ahref= "#home">Home</a>            <ahref= "#about">About Us</a>            <ahref= "#cel">Contact Us</a>        </Div>    </Header>    <DivNg-view=""class= "View"></Div></Body>

Look at the effect:

  

Angularjs route-Pass value $routeparams

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.