angular随笔
angular个别情况scope值不能改变或者不能绑定【如:指令内ctrl.$setViewValue()不能直接改变input的val值,该处需要使用scope.$apply】
如之前写的简单指令
var app = angular.module('hpapp', []);
app.directive('inputempty', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
var close = '<span class="clear"></span>';
elem.next().bind('click', function() {
ctrl.$setViewValue('');
ctrl.$render();
});
}
};
});
改变为
var app = angular.module('hpapp', []);
app.directive('inputempty', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
var close = '<span class="clear"></span>';
elem.next().bind('click', function() {
ctrl.$apply(function(){
ctrl.$setViewValue('');
});
});
}
};
});
以及下边的情况,在angular内部使用setInterval()以及setTimeout()都不能直接绑定
angular.module('app',[])
.controller('testController', function($scope) {
$scope.test = function() {
setTimeout(function() {
$scope.text = 'test';
console.log($scope.text );
}, 2000);
}
$scope.test ();
});
angular.module('app',[])
.controller('testController', function($scope) {
$scope.test = function() {
setTimeout(function() {
$scope.$apply(function() {
$scope.text = 'test';
console.log($scope.text );
});
}, 2000);
}
$scope.test ();
});
angular随笔的更多相关文章
- Angular随笔第二课
一. 列表表格以及其它迭代型元素 ng-repeat 可能是最有用的angular指令了,它可以根据集合中的项目一次创建一组元素的多份拷贝.不管在什么地方,只要你想创建一组事物的列表,你就可以使用这 ...
- Angular随笔第一课
一.调用angular 加载angular.js库(可以从google的cdn中加载类库,https://ajax.googleapis.com/ajax/libs/angularjs/1.0.4/a ...
- angular小技巧随笔
1. 重新刷新页面 同页面切换状态: $state.go('tab.index', {inviteId:inviteId}); self.location.reload();
- 浅谈HTML5单页面架构(一)——requirejs + angular + angular-route
心血来潮,打算结合实际开发的经验,浅谈一下HTML5单页面App或网页的架构. 众所周知,现在移动Webapp越来越多,例如天猫.京东.国美这些都是很好的例子.而在Webapp中,又要数单页面架构体验 ...
- angular之scope.$watch
某“大神”挖了个陨石坑,我于是乎似懂非懂的接手,玩了一个月angular.现在项目告一段落,暂别了繁重的重复性工作,可以开始回顾.认真的折腾下之前犹抱琵琶的angular. angular吸引人的特性 ...
- AngularJS进阶(二十五)requirejs + angular + angular-route 浅谈HTML5单页面架构
requirejs + angular + angular-route 浅谈HTML5单页面架构 众所周知,现在移动Webapp越来越多,例如天猫.京东.国美这些都是很好的例子.而在Webapp中,又 ...
- Angular使用总结 --- 模版驱动表单
表单的重要性就不多说了,Angular支持表单的双向数据绑定,校验,状态管理等,总结下. 获取用户输入 <div class="container-fluid login-page&q ...
- Angular环境搭建
Angular4 随笔(一)----环境搭建 1.下载node.js 第一步:在浏览器中搜索node.js官网(https://nodejs.org/zh-cn/),根据自己系统下载相应版本,下载完成 ...
- Angular的启动过程
我们知道由命令 ng new project-name,cli将会创建一个基础的angular应用,我们是可以直接运行起来一个应用.这归功与cli已经给我们创建好了一个根模块AppModule,而根模 ...
随机推荐
- NVIC优先级分组
挂起,解挂,使能,失能
- OpenFlow
What is OpenFlow? OpenFlow is an open standard that enables researchers to run experimental protocol ...
- Java Little Knowledge
1.Constructor running order of Base class and Derived class This is Alibaba's audition problem. clas ...
- 【jQuery】Jquery.cookie()
注意:如果不设置path,默认为当前路径,新建cookie $.cookie('name', 'value'); 新建带限制时间cookie $.cookie('name', 'value', { e ...
- 69 su -用户和工作组管理
su su命令用户和工作组管理 su命令用于切换当前用户身份到其他用户身份,变更时须输入所要变更的用户帐号与密码. 语法 su (选项) (参数) 选项 -c<指令>或--command= ...
- Beta版本冲刺———第四天
会议照片: 项目燃尽图: 1.项目进展: 今天解决的进度:新增加了一个撤销按钮,实现对上一步操作的撤销. 仍在进行对排行榜分数变更的实现. 2.每个人每天做的事情 郭怡锋:汇总工作进度,对此总结,进行 ...
- linux基础学习2
http://www.chengzhier.com <a href="http://www.chengzhier.com">橙汁儿网</a> 1. date ...
- 从 MySQL+MMM 到 MariaDB+Galera Cluster : 一个高可用性系统改造
很少有事情比推出高可用性(HA)系统之后便经常看到的系统崩溃更糟糕.对于我们这个Rails运行机的团队来说,这个失效的HA系统是MySQL多主复制管理器(MMM). 我们已经找寻MMM的替代品有一段时 ...
- Android基础知识总结
四大组件之一活动 活动状态 运行状态:活动处于栈顶 暂停状态:活动不处于栈顶,但仍然可见 停止状态:完全不可见 销毁状态:离开返回栈 生存期 onCreate() onStart():不可见到可见调用 ...
- jenkins 把包传到远程服务器上
首先我们在 一台服务器上部署svn,maven,jdk,tomcat,nexus,还有Jenkins. 这里我主要记录Jenkins. 首先我们从网上下载Jenkins的包 wget http://m ...