触发 ng-show 时调用函数? [英] Call a function when ng-show is triggered?
本文介绍了触发 ng-show 时调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用 ng-show 显示的内容显示一个灯箱,但我不知道如何触发灯箱 JS.我正在寻找类似的东西
ng-on-show="showLightbox()"
解决方案
我认为,最好$watch 绑定了 ng-show 的模型.
示例如下:
<div ng-show="isDisplayed">东西</div><button ng-click="isDisplayed = !isDisplayed">切换</button>var myApp = angular.module('myApp', []).controller('myCtrl', function($scope, $log) {$scope.$watch('isDisplayed', function(newValue, oldValue) {如果(新值!== 旧值){$log.log('改变了!');}});});
和小提琴
I want to show a lightbox with the content being revealed by ng-show, but I don't know how to trigger the lightbox JS. I'm looking for something like
ng-on-show="showLightbox()"
解决方案
I think, it would be better to $watch your model, on which ng-show is bound.
Here is example:
<div ng-app="myApp" ng-controller="myCtrl" ng-init="isDisplayed = true">
<div ng-show="isDisplayed">something</div>
<button ng-click="isDisplayed = !isDisplayed">Toggle</button>
</div>
var myApp = angular.module('myApp', [])
.controller('myCtrl', function($scope, $log) {
$scope.$watch('isDisplayed', function(newValue, oldValue) {
if (newValue !== oldValue) {
$log.log('Changed!');
}
});
});
and fiddle
这篇关于触发 ng-show 时调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文