Angularjs First Knowledge

Source: Internet
Author: User

Concept:

JavaScript-based ' client application framework ' enables us to develop Web applications more quickly and easily. Development for CRUD or spa single-page Web sites (frequent interaction of front-end data)

Scope:

$scope: Local

$rootScope: Global

bidirectional data binding: MVVM

$timeout usage similar to settimeout

But $timeout will change the value in the view

Ng-click similar to onclick

Ng-model

Listener: (Monitor data changes)

Three parameters:

objects to listen to

callback function----> has two parameters (new value, old value)

true: whether to listen in depth

Instance:

<!doctype html>

<meta charset= "UTF-8" >

<title>angularjs First Knowledge </title>

<!--introduce angularjs files--

<script type= "Text/javascript" src= "Angular.min.js" ></script>

<script type= "Text/javascript" >

var Phonecatapp =angular.module (' Phonecatapp ', []);

Phonecatapp.controller (' Phonelistctrl ', function ($scope) {

$scope. huawei={

' price ': 1499,

' num ': 1,

' fre ': 20

};

$scope. max = function () {

return $scope. huawei.price* $scope. Huawei.num;

}

$scope. $watch ($scope. Max,function (newval,oldval) {

newval>=100? $scope. huawei.fre=0: $scope. huawei.fre=20;

},true);

})

</script>

<body>

<div ng-controller= ' Phonelistctrl ' >

<p> Price: <input type= "text" ng-model= ' Huawei.price '/></p>

<p> Number: <input type= "text" ng-model= ' Huawei.num '/></p>

<p> Fee: <span></span>{{max () | Currency: ' ¥ '}}</p>

<p> Freight: <span></span>{{huawei.fre | Currency: ' ¥ '}}</p>

<p> total: <span></span>{{max () +huawei.fre| currency: ' ¥ '}}</p>

</div>

</body>



This article is from the "12897581" blog, please be sure to keep this source http://12907581.blog.51cto.com/12897581/1928368

Angularjs First Knowledge

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.