angular controller的一些用法
最近公司的项目是es6+angular。其中的代码格式还在逐步摸索中。感谢今天同事每天帮我解惑。
今天简单梳理一下controller的一些用法
之前看书所熟知的都是
这是最普通的一种
//html
<html ng-app='app'>
<div ng-controller='mycontroller'></div>
</html>
//js
<script>
angular.module('app').controller('mycontroller')
</script>
然而在项目中运用了es6 angular就变形了
//index.js
import angular from 'angular';
import uiRouter from 'angular-ui-router';
angular.
moduler('XXX',[
ui-Router
])
.controller('cookieConteroller',$cookiex => { //这个里面的'cookieConteroller'一定在页面里面有所变现
'ngInject'; //这个可以理解为防止压缩
<----逻辑代码--->
})
如果是模板形式加载的,肯定会表现在Router里面
//routers.js
export const XXX = {
state: 'xxx.home'
config: {
url:'/home',
templateUrl: '模板页面',
controller: '模板页面的名字',
controllerAs: '模板页面的别名 一般用vm,$ctrl'
}
}
以上.
angular controller的一些用法的更多相关文章
- angular中$q.all用法
$q.all是用于执行多个异步任务进行回调,它可以接受一个promise的数组,或是promise的hash(object).任何一个promise失败,都会导致整个任务的失败. 例1:接受一个pro ...
- angular controller的使用
在angular.js最常用的模块就是控制器了,通常我们会这样使用: var myAppModule = angular.module('myApp', []); myAppModule.cont ...
- angular controller as syntax vs scope
今天要和大家分享的是angular从1.2版本开始带来了新语法Controller as.再次之前我们对于angular在view上的绑定都必须使用直接的scope对象,对于controller来说我 ...
- Angular JS中 Promise用法
一.Promise形象讲解A promise不是angular首创的,作为一种编程模式,它出现在1976年,比js还要古老得多.promise全称是 Futures and promises. 而在j ...
- angular $q服务的用法
Promise是一种和callback有类似功能却更强大的异步处理模式,有多种实现模式方式,比如著名的Q还有JQuery的Deffered. 什么是Promise 以前了解过Ajax的都能体会到回调的 ...
- angular controller之间通信方式
对于日常开发中,难免会有controller之间通信需求.对于controller之间通信有两种方式可以做到. 用 Angular 进行开发,基本上都会遇到 Controller 之间通信的问题,本文 ...
- Angular @HostBinding()和@HostListener()用法
@HostBinding()和@HostListener()在自定义指令时非常有用.@HostBinding()可以为指令的宿主元素添加类.样式.属性等,而@HostListener()可以监听宿主元 ...
- angular中的ng-options 用法
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- angular controller 之间的通信方式
AngularJS中的controller是个函数,用来向视图的作用域($scope)添加额外的功能,我们用它来给作用域对象设置初始状态,并添加自定义行为. 当我们在创建新的控制器时,angularJ ...
随机推荐
- Windows 2008 R2无法打补丁
遇到了Windows 2008 R2无法打补丁,并且控制台上的feature和roles都是error 可下载这个补丁进行修复: System Update Readiness Tool for Wi ...
- shell脚本——项目2
案例名称:发送告警邮件 背景: 外部邮箱的服务器(163等) 安装mailx(yum) 配置邮箱信息 vim /etc/mail.rc #配置自己的邮箱信息 set from=18906534060@ ...
- APscheduler总结
APscheduler使用总结 APscheduler是执行定时任务的python库,其作用可以代替Linux系统下的crontab,github上有该库的例子. APsheduler基本使用 该模块 ...
- 为什么32位系统最大支持4G内存??我自己悟出来了 终于 。。。。。
今天突然开窍了,想通了..... 以下是我的抽象想法: 32位系统 这个 多少位 指的是 硬件的 一次性发送过来的位数,一个字节 等于8位,内存的一个存储单元就是一个字节,即8位. 也可以这样来想这个 ...
- hdu 3790(SPFA)
最短路径问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- uva11019矩阵匹配器D316
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #inclu ...
- 允许root用户登录ssh
使用普通用户登录Ubuntu系统,打开命令行窗口 更改root用户密码,命令:sudo passwd root 首先输入当前用户的密码 然后输入root账户的密码 确认root用户的密码 编辑ssh的 ...
- Python的扩展接口[1] -> 串口通信
串口通信 / Serial Communication 1 串口简介 / Serial Introduction 串行接口(Serial Interface)简称串口,通常为COM接口,数据发送方式为 ...
- Python的程序结构[2] -> 类/Class[0] -> 类的特殊属性
类的特殊属性 / Special Property of Class Python 中通过 class 进行类的定义,类可以实例化成实例并利用实例对方法进行调用. 类中还包含的一些共有的特殊属性. 特 ...
- Codeforces 1029 E. Tree with Small Distances(树上dp)
题目直通车:http://codeforces.com/problemset/problem/1029/E 思路大意:在树上做dp,依次更新ar数组,ar[i]表示以i为根节点的子树对答案的最小贡献值 ...