Open HanSummer opened 7 years ago
一切都从模块化开始
一个模块包含:
配置 config router
过滤器 filter
指令 directive
服务 factory service provider value
控制器 controller
比如 $scope
var myApp = angular.module('myApp', []);
myApp.controller('myController',['$scope',function(scope){
scope.model = {
text: 'Hello World'
}
}])
比如
<!DOCTYPE html>
<html ng-app='myApp'>
<head>
<meta charset='utf-8'>
<title>demo</title>
</head>
<body>
<input type='text' ng-model='model.text'>
<div>输入的值: {{model.text}}</div>
</body>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('myController',['$scope',function(scope){
scope.model = {
text: 'Hello World'
}
}])
</script>
</html>
Angular内置指令大约60个
<!DOCTYPE html>
<html ng-app='myApp'>
<head>
<meta charset='utf-8'>
<title>demo</title>
</head>
<body>
<my-hello></my-hello>
</body>
<script>
var myApp = angular.module('myApp', []);
myApp.directive('myHello',function(){
return {
restrict: 'E',
template: '<div>hello world</div>'
}
})
</script>
</html>
模块化
依赖注入
双向绑定
指令
MVC