1. 程式人生 > >angular基礎(一)

angular基礎(一)

–*指令 end

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<script src="angular.min.js"></script>
<style>
    .custom-html{color:red;}
</style
>
</head> <body> <div ng-app="myApp" ng-controller="myCtrl" ng-init="cost=5;num=4;address={province:'shenzhen',detail:'nanshan'};age=[25,26,27]"> 姓:<input type="text" ng-model="firstName"><br> 名:<input type="text" ng-model="lastName"><br> 全名:
{{firstName
+ ' ' + lastName}}
<br> <ul ng-repeat="value in age"> {{value}}歲? </ul> 年齡:{{age[2]}} <br> 4*5 = {{cost * num}} <br> 居住地:{{address.province+' '+address.detail}} <br> <ul ng-repeat="value in country"> {{value.name}} : {{value.num
}}
枚金牌 </ul> <custom-html></custom-html> <!-- E --> <div custom-html></div> <!-- A --> <div class="custom-html"></div> <!-- C --> <!-- M replace:true --> <!-- directive: custom-html --> </div> <script> var app = angular.module('myApp',[]); //demo中ng-app為‘myApp’元素是angular應用程式 app.controller('myCtrl',function($scope){ //myApp應用程式是由什麼資料內容控制的 $scope.firstName = "SUN"; $scope.lastName = "GANG"; $scope.country = [ {num:25,name:'中國'}, {num:3,name:'USA'}, {num:0,name:'JP'}, ] }); app.directive("customHtml",function(){ return { restrict : "AECM", replace : true, template:"<h3>directive用於自定義標籤內容!</h3>" } }) </script> </body> </html>