如何在angular js指令之后触发回调
How to trigger callbacks after angular js directives
我是Angular JS的新手,我正试图弄清楚如何在指令完成后进行操作。
例如,有一个指令:ng mousemove。如果我想在鼠标移动时更改某些内容的颜色,请添加ng-mousemove="mouseMoveFunc()"
并更改控制器中的相关css属性。但是把它改回来怎么样?(没有ng mousemoveStop指令)
我已经遇到过几次了,所以我想我错过了一些关于它应该如何工作的东西。
在控制器中,您可以执行以下操作:
HTML
<div ng-app="myApp">
Move the mouse on blue box. If you stop to move or leave the box, the
color comes back to original color.
<div ng-controller="mycontroller"
style="height:200px"
ng-style="mystyle()"
ng-mousemove="mouseMoveFunc()">
</div>
</div>
Javascript
angular.module("myApp",[])
.controller("mycontroller",["$scope","$timeout",function($scope, $timeout){
$scope.mystyle = function(){
if(queue<1){
return {"background":"blue"};
}else{
return {"background":"black"};
}
};
var queue=0;
$scope.mouseMoveFunc = function(){
queue++;
$timeout(function(){
queue--;
},100);
}
}]);
演示
相关文章:
- 如何在`window.open`之后执行回调
- $.mobile.changePage 之后的回调函数通过 AJAX 加载
- 如何在angular js指令之后触发回调
- nodejs:setImmediate 回调在 setTimeout(fn, 0) 之后执行,与 nodejs 文档描述
- 在 ng 选项之后完成控制器内部的回调函数
- 在 AJAX 回调之后,onblur 会返回到原始(或更新)字段
- 无法在 .attr 之后回调函数
- $.each 之后的回调带有动画
- 异步:在回调中获取 For 之后的空数组
- array.forEach之后的回调函数
- Node.js for 循环,带有回调,之后同步执行
- ng-repeat之后的Angular JS回调是动态完成的
- 两个异步函数之后的回调
- 在ajax回调函数的每个循环之后附加输出
- fadeIn作为fadeOut之后的回调函数没有按预期工作
- 如何在jquery中准备好$.mobile.changePage之后运行回调函数
- 在javascript中完成所有回调之后,我该如何执行一些东西
- 在PreSaveAction方法之后执行的ECMAScript回调方法
- 无论如何,在完成(回调)ScriptManager.RegisterStartupScript之后调用c#方法
- 在jQuery.trigger()函数之后回调