AngularJs-02-表达式和作用域

<!DOCTYPE html>
<html lang="zh" ng-app>
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <script src="../bower_components/angular/angular.js" type="text/javascript" charset="utf-8"></script>
    <title>{person.name}}-AngularJs-表达式和作用域</title>
</head>
<body ng-init="name='bilaisheng';age=10">
     
    {{name}}
    {{age}}
    
    <div ng-init="person={name:'bilaisheng',age:18}"></div>
    {{person.name}}
    {{person.age}}
        
    <div ng-init="arr = [1,2,3,4,5,6,7,8,9]"></div>
    <h1>数组第一个元素:{{arr[0]}}</h1>
    <h1>数组最后一个元素{{arr[arr.length-1]}}</h1>
    <h1>数组的长度{{arr.length}}</h1>
    <ol ng-repeat="c in arr">
        {{c}}
    </ol>
    
    
    <div ng-init="carr = [{username:'bilaisheng',age:18},{username:'three',age:30}]"></div>
    <h1>数组第一个元素:{{carr[0].username}}</h1>
    <h1>数组最后一个元素:{{carr[carr.length-1].age}}</h1>
    <ul ng-repeat="c in carr">
        <li>{{c.username}}--->{{c.age}}</li>
    </ul>
    
    
    <script type="text/javascript">
        /**
         * 1. 表达式和作用域
         * ng-init : 该指令用以初始化一些作用域的数据,它的数据挂载到全局作用域$rootScope
         */
    </script>
    
</body>
</html>
上一篇:apache2-PHP编辑和显示.txt文件中的文本


下一篇:Perl脚本执行方法小结