Cha*_*har 5 angularjs angularjs-ng-click
我的控制器里面有两个功能
$scope.first = function()
{
console.log("first");
}
$scope.second = function()
{
console.log("hello");
}
Now in my template i give call to first function
<button ng-click="first()">click</button>
Run Code Online (Sandbox Code Playgroud)
现在我希望我的第一个函数完成执行后,第二个函数自动开始执行而不需要任何点击.
即单击第一个函数执行,然后分别执行第二个函数.
Tar*_*gar 10
只需调用分隔的函数即可 ;
<button ng-click="first();second()">click</button>
Run Code Online (Sandbox Code Playgroud)
或者,您可以执行以下操作:
function first() {
// Do stuff
}
function second() {
// Do stuff
}
$scope.runBoth = function () {
first();
second();
}
Run Code Online (Sandbox Code Playgroud)
这种方法的好处是,您可以侦听first()返回,并基于second()的运行/跳过执行等。
另外,通过将first()和second()保留为javascript函数,就不会添加不必要的观察者(假设您未在其他地方使用first()和second())。
归档时间: |
|
查看次数: |
10174 次 |
最近记录: |