Angularjs Quick Start (ii)

Source: Internet
Author: User
Tags html form

In the example of the previous section, $scope we did not create this object, the direct binding can get inside the object, this style follows a design pattern called Dimitri Law.

Then angular also has a very powerful function called "instruction".

You can. Templates are written in HTML form, and there are some things that are not part of the HTML specification, such as the Ng-controller introduced. Ng-model, let's look at a similar shopping cart example:

1 <HTMLng-app= ' My-app '>2     <Head>3         <Tiltle>My Shopping Cart</title>    4     </Head>5     <BodyNg-controller= ' Cartcontroller '>6         <H1>My order</H1>7         <Div ng-repeat= ' Item in items ' >8             <span>{{Item.title}}</span>9             <inputNg-model= ' item.quantity '>Ten             <span>{{item.price|currency}}</span> One             <span>{{Item.price * item.quantity|currency}}</span> A             <ButtonNg-click= "Remove ($index)">Remove</Button> -         </Div> -         <Scriptsrc= "Angular.js"></Script> the         <Script> -             functionCarcontroller ($scope) { - $scope. Items=[ - {title:'Paint Pots', Quantity:8, Price:3.33}, + {title:'Pack Pots', Quantity:5, Price:2.33},     - {title:'pedbbles Pots', Quantity3,price: A} +                 ]; A $scope. Remove=function(index) { at $scope. Items.splice (Index,1); -                 } -             } -         </Script> -         </Body> -     </HTML>

Here are a few explanations of where the first one is ng-app= ' My-app ', which means the entire page is Angular admin page

The second, ng-repeat= ' item in items ' means that each element in the items array copies a copy of the DOM structure of <div>, including the div itself, items have three groups, so there are now three Div

Third, {{item.title}} binds data through {{}} and creates a binding relationship with ng-model= ' item.quantity '

Fourth one,

{{item.price|currency}}
{{Item.price * item.quantity|currency}} Filter
Currency is a currency filter that is built-in and it can be formatted for US dollars.

Fifth one,
ng-click= "Remove ($index)"
Delete button, can delete the shopping cart items.

Angularjs Quick Start (ii)

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.