AngularJS:ng-show用法 [英] AngularJS : ng-show usage

查看:50
本文介绍了AngularJS:ng-show用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循ng-show和ng-hide的工作方式.我希望在我的REST调用成功时显示一个表单,如果调用返回一个空值,则会显示一条错误消息.

我还经历了 AngularJS:ng-show/ng-hide

,但仍未遵循它们的确切工作方式.有人可以帮忙吗?

解决方案

使用承诺

  var promise = service.Method();promise.then(function(response){//展示$ scope.elementVisibility = true;$ scope.errorMsg = false;},函数(原因){//隐藏$ scope.elementVisibility = false;$ scope.errorMsg = true;});< form ng-show ="elementVisibility"></form>< div ng-hide ="errorMsg"></div> 

I am trying to follow how ng-show and ng-hide work. I want a form to be shown when my REST call is a success and an error message if call returns me a null value.

I also went through AngularJS: ng-show / ng-hide

but still not following how they exactly work. Can anyone help?

解决方案

Using a promise

        var promise = service.Method();
         promise.then(function(response) {
            //Show
            $scope.elementVisibility = true; $scope.errorMsg = false;
         }, function(reason) {
            // Hide
            $scope.elementVisibility = false; $scope.errorMsg = true;
        });


    <form ng-show="elementVisibility"></form>
    <div ng-hide="errorMsg"></div>

这篇关于AngularJS:ng-show用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆