/** * Created by Answer1215 on 12/21/2014. */ angular.module('app', []) .controller('FirstCtrl' , function(){ var vm = this; vm.message = "I am the first controller"; }) .controller('SecondCtrl', function() { var vm = this; vm.message = "I…
原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular中,controller是一个javascript 函数(type/class),被用作扩展除了root scope在外的angular scope(http://www.cnblogs.com/lcllao/archive/2012/09/23/2698651.html)的实例.当我们或者angular通过scope.$new API(h…
说明 本文主要说明,在angularJS框架使用中,angularJS 路由加载js controller 未定义 解决方案. 路由 $routeProvider 异步加载js 路由的基本用法,请查看官方文档,下面实例只说明,懒加载用法. 实例使用版本: angularJS:1.7.6 ocLazyLoad:1.1.0 片段说明 通过路由懒加载js,需要引用第三方ocLazyLoad库加载,并且修改被加载脚本代码,防止控制器出现未定义现象. 定义 ocLazyLoad 库 angular.mod…
ng-repeat is similar to foreach loop in C#. Let us understand this with an example. Here is what we want to do. 1. For each employee we have in the employees array we want a table row. With in each cell of the table row we to display employee Firstna…
ng-include directive is used to embed an HTML page into another HTML page. This technique is extremely useful when you want to reuse a specific view in multiple pages in your application. The value of ng-include directive can be the name of the HTML…
The ng-init directive allows you to evaluate an expression in the current scope.  In the following example, the ng-init directive initializes employees variable which is then used in the ng-repeat directive to loop thru each employee. In a real world…
原文: http://www.cnblogs.com/whitewolf/p/3493362.html 这篇国外的文章也非常好: http://codetunnel.io/angularjs-controller-as-or-scope/ 有些人觉得即使这样我们的controller还是不够POJO,以及对于coffescript爱好者不足够友好,所以在angular在1.2给我带来了一个新的语法糖这就是本文将要说的controller as的语法糖,修改上面的demo将会变成: 1 2 3 4…
原文:http://www.cnblogs.com/lvdabao/p/3379659.html 一.模板中可使用的东西及表达式 模板中可以使用的东西包括以下四种: 指令(directive).ng提供的或者自定义的标签和属性,用来增强HTML表现力. 标记(markup).即双大括号{{}},可将数据单向绑定到HTML中. 过滤器(filter).用来格式化输出数据. 表单控制.用来增强表单的验证功能. 其中,指令无疑是使用量最大的,ng内置了很多指令用来控制模板,如ng-repeat,ng-…
'use strict'; angular.module('app.core').directive('ueditor', [function () { return { restrict: 'A', require: 'ngModel', link: function (scope, element, attrs, ctrl) { var _initContent = ''; var editor; var editorReady = false; ctrl.$render = functio…
一.Controller的创建 angular.controller("name",funtion($scope){ }) 1.name:控制器的名称(建议参考Java包的命名规范:点的方式进行命名): 2.function:回调函数的构造方法(实际是对象,主要考虑到类的调用): 3.$scope相当于mvvm模式的viewmodel,支持变量.函数: 3.1.$ccope的由来: $injector注射完成后创建的$rootScope(根作用域root Viewmodel,$scop…
angluar的编译有以下几种方式: ng build  常规的压缩操作    代码体积最大 ng build --aot   angular预编译      代码体积较小 ng build --prod   angular预编译    代码体积最小,访问速度最快 --prod 默认 开启了--aot ,所以在使用--prod 和 --prod --aot是一样的. 关于JIT和AOT,复制了知乎上的一段话,讲的很好. JIT和AOT的思想都一样.在JAVA中,JIT(Just In Time即…
在做angularjs 的UI 时,我们经常会遇到一个页面之间有几个controller,在controller 之间share 公共的一些数据和方法就变得比较困难,目前推荐的做法是创建一个service, 在service 中存储公共的数据,然后把service 注入到controller中来达到share 数据的目的. 下面是最简单的一个sample 列子 angularjs 模板页面, 有userContoller 和 customerController,我们将在这两个controlle…
所谓的延迟加载通常是:直到用户交互时才加载.如何实现延迟加载呢? 需要搞清楚三个方面: 1.html元素的哪个属性需要延迟加载?2.需要对数据源的哪个字段进行延迟加载?3.通过什么事件来触发延迟加载? 自定义的Directive的页面表现大致是这样: <ul> <li ng-repeat="cust in customers" delay-bind="{{::cust.street}}" attribute="title" tr…
页面上 : ui-sref="home.dataAnalysis({role:'thirdpart:tokenverify',menuType:'a'})" 路由设置 .state('home.dataAnalysis', { url: '/dataAnalysis?role&menuType', views: { 'footer@home':{ templateUrl: 'app/main/footer.html' }, 'rightside@home': { templat…
1.没有对应的控制器 2.有控制器但是路径没有配对…
原版地址:http://code.angularjs.org/1.0.2/docs/guide/directive Directive是教HTML玩一些新把戏的途径.在DOM编译期间,directives匹配HTML并执行.这允许directive注册行为或者转换DOM结构. Angular自带一组内置的directive,对于建立Web App有很大帮助.继续扩展的话,可以在HTML定义领域特定语言(domain specific language ,DSL). 一.在HTML中引用direc…
AngularJS 通过被称为 指令 的新属性来扩展 HTML. 正如你所看到的,AngularJS 指令是以 ng 作为前缀的 HTML 属性. HTML5 允许扩展的(自制的)属性,以 data- 开头. AngularJS 属性以 ng- 开头,但是您可以使用 data-ng- 来让网页对 HTML5 有效. 以下列举了一些指令,并不一定常用,但是都有用! 有些指令相关的demo,有兴趣的可以下载,github地址:https://github.com/392468072/demo 自带指…
AngularJS之directive AngularJS是什么就不多舌了,这里简单介绍下directive.内容基本上是读书笔记,所以如果你看过<AngularJS up and running>,那么这个可以忽略. 1.在AngularJS中,directives有两个主要的类型:1⃣️UI展示的修改器,如ng-show.ng-model2⃣️可复用的组件,如菜单.轮播器.taps等. 2.directives定义: angular.module('stockMarketApp', [])…
需求背景:         directive模块化某表单信息,但表单信息可加入多条.此时就涉及到clone directive. 解决方式:         能够通过使用angularjs中$compile来进行clone directive.clone direcitve中常涉及到数据的绑定. 详细方法: tw.factory('DirectiveUtil', [function() { var DirectiveUtil = {}; DirectiveUtil.DirectiveBuild…
前面提到了angularjs的factory,service,provider,这个可以理解成php的model,这种model是不带html的,今天所说的directive,也可以理解成php的model,也可以理解成插件,只不过这种model是带html的,例如:php的分页函数. 一,angularjs directive的常用格式,以及参数说明 1,直接return phonecatDirectives = angular.module('phonecatDirectives', [])…
说到Angularjs directive即指令,可以这么说Angularjs的灵魂就是指令,学会Angularjs指令那么你的Angularjs的武功就修炼了一半了,当然这只是鄙人的一点点独到见解,废话不多说,以下是Angularjs 指令的运用及源码实现解读. 学习Angularjs directive那么我们要带3个问题来学习: 1. 什么是angular 指令?2. 指令如何定义存储的?3. 指令如何编译运行的? 1.首先第一点解读什么是指令: At a high level, dire…
AngularJS中,当需要自定义Directive时,通常返回一个对象,就像如下的写法: angular.module('modulename') .directive('myDirective', function(){ return { restrict: 'EA', //E表示element, A表示attribute,C表示class,M表示commnent,即注释 scope:{ title: '@' //@读属性值,=双向绑定,&用户函数 } template: '<div&g…
一.directive中的scope directive无疑是AngularJS中比较复杂难懂的部分,而directive中个scope更是其中最复杂的部分了,尤其是在嵌套directive中互相通讯的时候. 单独的directive中,scope概念还是比较简单的,此时scope的三种取值情况为: scope:false  此时,directive没有独立的scope对象,link函数中引用的scope对象来自于当前节点的默认controller scope:true  此时,directiv…
指令Directive是AngularJS最重要的核心.我用AngularJS用的并不是很深,一直以来也是在使用中摸索,从一开始的什么都不懂,查不到系统的资料,到开始使用一些简单的数据绑定{{}},到发现ng-bind比双括弧好用是因为DOM加载速度的问题,到发现简单的ng-repeat能完成很多事情,到用它来做表单验证时发现ng-form好好用,到... 总之,对AngularJS从无知到有一定认可的现在,我觉得我使用它最大的好处就是数据绑定,将数据绑定在$scope里面然后想怎么写就怎么写.…
前沿 最近在angularjs项目当中,看到 controller 好多都是重复性的代码,在 controller 当中有好多代码很相似 function(比如 controller 下的 CRUD 方法),重复性工作太多.后来想,可不可以提出一个service ,但仔细想想,这些CRUD 本来就是从 Service 中调用的,如果在提出Service,会造成 Service 比较混乱,职责不清晰 . 因为自己做过一些后端,借助后端的思想,是不是可以 controller 继承. \(contr…
调试页面 ng serve 正常 ng build 也正常 ng build --prod 异常:Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' 开始以为是以前那样,引用错了路径或少引用了东西. 搜了好多资料,发现是 angular-cli 的版本有点低了(因为用了最新的material) 找到原因了,问题就很容易解决了 第一步: rm -rf node_modules/ 第二部: npm…
供应者(Providers) Each web application you build is composed of objects that collaborate to get stuff done. These objects need to be instantiated and wired together for the app to work. In Angular apps most of these objects are instantiated and wired to…
/** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http://angularjs.org function toKeyValue(obj) { var parts = []; forEach(obj, function(value, key) { if (isArray(value)) { forEach(value, function(arrayValue) { parts.push(encodeUriQ…
MVVM大比拼之AngularJS源码精析 简介 AngularJS的学习资源已经非常非常多了,AngularJS基础请直接看官网文档.这里推荐几个深度学习的资料: AngularJS学习笔记 作者:邹业盛 .这个笔记非常细致,记录了作者对于AngularJS各个方面的思考,其中也不乏源码级的分析. 构建自己的AngularJS .虽然放出第一章后作者就写书去了.但这第一部分已经足以带领读者深入窥探angularJS在核心概念上的实现,特别是dirty check.有愿意继续深入的读者可以去买书…