问题与ngShow [英] Issue with ngShow

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

问题描述

我与ngShow以下问题。我收到的响应作为JSON从$ http.get
构建使用ngRepeat几个DOM元素。所有这一切工作正常。从我的控制器只适用

I have following problem with ngShow. I receive response as a jSON from $http.get and construct several DOM elements using ngRepeat. All this working properly. From my controller a just apply:

    $http.get(requestUrl).success(function (data) {
        $scope.results = data.results;
    });

data.results是这样的一个对象:

data.results is a object like this:

{ 
   "someProp": ["item1", "item2", "item3"],
   "someProp1": ["item1", "item2", "item3"]
}

这是我的模板我尝试使用ngShow这样的:

From my template I try to use ngShow like this:

<table ng-show="Object.keys(results).length > 0">

和这样的:

<table ng-show="Object.keys($scope.results).length > 0">

由于没有运气。

With no luck.

<table ng-show="true">

<table ng-show="false">

正常工作。

如此看来,这个问题是在EX pression。我将是任何帮助非常感激。

So it seems that the problem is in the expression. I would be very grateful for any help.

推荐答案

这不计算除权pression里面的 Object.keys 的功能,因为它是不实际位于的范围。你能解决这个问题的方法之一是通过指定对象的范围。

It does not evaluate the Object.keys function inside of the expression as it is not actually located on the scope. One way you can get around this is by assigning the Object to the scope.

$scope.Object = Object;

和您的视图中

<div ng-show="Object.keys(results).length > 0">
    {{Object.keys(results).length}}
</div>

这篇关于问题与ngShow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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