菜鸡学AngularJS 03 语法简介
2016-07-20 本文已影响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>