您的位置:首页 > Web前端 > JavaScript

angular.js基础学习

2017-01-01 00:02 423 查看
1 MVC思想,M->module, V->view,C->control.

前后台各司其职。

2 angular的特点

以数据为中心,讲数据精确到类型。

操作数据,数据双向绑定,使用的数据和设置数据的位置是互通的

angular下的数据是不能重复的。

依赖注入, 把函数中的参数固定写死。位置是不固定的。

3 angular中的this指向问题

首先JS中的this指向 可以用 call 和 apply.

而在angular中 用 angular.bind

4 angular.forEach(arr,function(val,index){})------>循环(数组/json)。

//---------指令

5 ng-repeat----------->循环

	ng-repeat="name in arr"


6 ng-app 开启页面的angular模式。

7 ng-init 数据初始化 ng-init="a=12"

8 ng-model 创造数据  只能在 input 中使用

<inputtype="text"ng-model="a"/>{{a}}

9ng-bind 展示部分.

10 ng-show/hide. ng-show--->默认属性是hide.

11 ng-click等等 事件都可以

12 控制器

var app=angular.module('app',[]);

app.controller('aaa',function($scope){})

12 自定义过滤器

app.filter('name',function(){})

13 自定义指令

app.directive('name',function(){});

14 

配置路由:
1. 引入js文件
<script src="js/angular-route.js"></script>

2. 设置配置:
//配置路由
app.config(function($routeProvider){
$routeProvider.when('/index',{
templateUrl:'a_1.html'
}).when('/about',{
templateUrl:'a_2.html'
}).otherwise({

4000
redirectTo:'/index'
});
});

15
引入外部模板:
<header ng-include="'2.html'"></header>
ng-include src="'header.html'"
引入本页面模板
<script type="text/ng-template" id="demo">
<h3>这是h3</h3>
</script>
<header ng-include="'demo'"></header>
16 数据交互
$http
可以get() post()   jsonp()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: