美文网首页
菜鸡学AngularJS 03 语法简介

菜鸡学AngularJS 03 语法简介

作者: 菜鸡 | 来源:发表于2016-07-20 14:59 被阅读26次

    方法1:ng-init 初始化应用时定义一个变量

    <p ng-init = {{a=10;}}>{{a}}</p> 
    

    方法2:在控制器里面定义

    PS:1. 多个
    <!doctype html>
    <html ng-app = "myapp">
    <head>
        <script src="http://code.angularjs.org/angular-1.0.1.min.js"></script>
    </head>
    <body>
        <p ng-controller="TestController">{{Nmber +' '+ Str +' '+ Now +' '+ Arr[2] +' '+ Obj.age }}</p>
    </body>
    <script>
        var app = angular.module('myapp', []);
        app.controller('TestController', function($scope) {
            $scope.Nmber = 123;
            $scope.Str = "abc";
    
            var Now = new Date();
            $scope.Now = Now.getHours() +':'+ Now.getMinutes() +':'+ Now.getSeconds();
    
            $scope.Arr = ['arr1','arr2','arr3'];
            $scope.Obj = {name:"jack",'age':15};
        });
    </script>
    </html>

    相关文章

      网友评论

          本文标题:菜鸡学AngularJS 03 语法简介

          本文链接:https://www.haomeiwen.com/subject/wnpvjttx.html