<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</div>
<script>
*var app = angular.module('myApp', []);*
app.controller('myCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});
</script>
为什么我们使用&#34; var app = angular.module(&#39; myApp&#39;,[]);&#34;这个?特别是我需要知道这行中的方括号???
答案 0 :(得分:3)
第一个参数是模块名myApp
。第二个参数是此模块所依赖的模块名称数组。空方括号表示此模块没有任何依赖关系。
var app = angular.module('myApp', []);