Angularjs-2 (basic)
2016-07-05 17:21
555 查看
Angular Template
Angular template is very useful in Dynamic APP. They are written with HTML, contain angular specific elements and attributs, and can be added or dropped in the page. More specifically, Dynamic View = Template + Controller + ModelTemplate’s elements and attributs
Directives, Markup:{{expressions}}, Filter, Form controls
Add templates into pages
We need to use ng-include directive to fetch, comile and include an external HTML fragment
Like:
<div ng-include='menu.html'></div>or
<ng-include src='menu.html'></ng-include>
Note: traditional web sites would contain multiple pages. When users make a request, the server will send the corresponding html page to the users. This is not efficient. So the single page applications are emerging. Instead of reponding a page, SPA only respond with JSON data, the single page will repond according to this JSON data or replace some templates to represent different views. (One challeng of SPA is that we should speed up the initial page load.)
Angular ngRoute and SPAs
SPA (single page application)Views = Templates + Controller + Model. Single page, single view, dynamic app
Deep linking: Hyperlink that specifices a link to a searchable or indexed piece of web content
Example: http://…….//index.html #/menu/0 hash
Any changes to the hash portion does not cause a page reload
The $location service
Exposes the current URL in the browser address bar;
Synchronizes the URL with the brower when user changes the address bar;
Allows you to manipulate the hash portion of a URL;
Routing
Mapping the path portion of a URL to a handler for that particular route
Route is the hash portion of the URL in SPAs
ngRoute Module
Installing the module: bower intall angular-route -S
Manages the interaction between the $location service and the rendered view
$routeProvider
Enables mapping from the routes to handlers, which are objects defining template URL and controoler
An example: routeProvider and routeParams
Moreover, we need ng-view that works together with route service to include the template to our main page
Angular UI-Router
Except ngRoute, UI-Router can be more powerful.The detail introduction is as follow
相关文章推荐
- angular.element方法汇总
- 深入学习JavaScript的AngularJS框架中指令的使用方法
- 仿Angular Bootstrap TimePicker创建分钟数-秒数的输入控件
- Angular用来控制元素的展示与否的原生指令介绍
- 使用angular写一个hello world
- vue,angular,avalon这三种MVVM框架优缺点
- 使用Angular和Nodejs、socket.io搭建聊天室及多人聊天室
- AngularJS页面访问时出现页面闪烁问题的解决
- 利用CSS3在Angular中实现动画
- 初识angular框架后的所思所想
- 实例剖析AngularJS框架中数据的双向绑定运用
- 理解Angular数据双向绑定
- Angular中的Promise对象($q介绍)
- Angular实现form自动布局
- 在AngularJS中使用jQuery的zTree插件的方法
- 自定义Angular指令与jQuery实现的Bootstrap风格数据双向绑定的单选与多选下拉框
- angular简介和其特点介绍
- AngularJS使用angular-formly进行表单验证
- 详解JavaScript的AngularJS框架中的作用域与数据绑定
- 给angular加上动画效遇到的问题总结