页面使用argularJs的驱动形式
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<meta charset="utf-8" />
<title>数据正向绑定</title>
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript" src="angular.js"></script>
</head>
<body>
<div ng-controller="TestCtrl">
<input type="text" value="" id="a" />
</div>
<script type="text/javascript">
var TestCtrl = function(){
console.log('ok');
}
//angular.bootstrap(document.documentElement);
angular.module('MyApp', [], function(){console.log('here')});
</script>
</body>
</html>
ng-app="MyApp" 放在html标签内,指定范围。
App 就是 ng 概念中的一个 Module 。对于 Controller 来说, 如果不想使用全局函数,也可以在 app 中定义:
var app = angular.module('MyApp', [], function(){console.log('here')});
app.controller('TestCtrl',
function($scope){
console.log('ok');
}
);