Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng显示isArray表达式_Javascript_Html_Angularjs - Fatal编程技术网

Javascript ng显示isArray表达式

Javascript ng显示isArray表达式,javascript,html,angularjs,Javascript,Html,Angularjs,仅当模型字段为数组时,我想渲染选择标记。我有以下代码: HTML: 演示: 正如您所看到的,单击按钮后,我只得到span和tabObj.foo作为文本。 如何获取选择标签 如果我将tabObj.foo值更改为简单字符串('abc'),并使用ng show=“tabObj.foo.length>0”检查我始终获得选择标记(不查看span)-请查看这里是更新的JSFIDLE,您必须定义isArray 这是您必须定义iArray的更新JSFIDLE 我希望这对你有帮助。多谢各位 函数showC

仅当模型字段为数组时,我想渲染
选择
标记。我有以下代码:

HTML:

演示:

正如您所看到的,单击按钮后,我只得到
span
tabObj.foo
作为文本。 如何获取
选择
标签



如果我将
tabObj.foo
值更改为简单字符串(
'abc'
),并使用
ng show=“tabObj.foo.length>0”
检查我始终获得
选择
标记(不查看
span
)-请查看这里是更新的JSFIDLE,您必须定义isArray


这是您必须定义iArray的更新JSFIDLE


我希望这对你有帮助。多谢各位

函数showCrtl($scope){
$scope.isArray检查=angular.isArray;
$scope.showCon=function(){
$scope.tabObj={'foo':['AA','BB']};
}
}

按钮1
{{tabObj.foo}}

我希望这会对您有所帮助。多谢各位

函数showCrtl($scope){
$scope.isArray检查=angular.isArray;
$scope.showCon=function(){
$scope.tabObj={'foo':['AA','BB']};
}
}

按钮1
{{tabObj.foo}}
您的
ng show=“isArray(tabObj.foo)”
在html中不是这样直接工作的。您可以再创建一个变量并检查其值

函数showCrtl($scope){
$scope.test=false;
$scope.showCon=function(){
$scope.tabObj={'foo':['AA','BB']};
$scope.test=Array.isArray($scope.tabObj.foo);
警报(“字段是数组吗?”+$scope.test);
}
}

按钮1
{{tabObj.foo}}
您的
ng show=“isArray(tabObj.foo)”
在html中不是这样直接工作的。您可以再创建一个变量并检查其值

函数showCrtl($scope){
$scope.test=false;
$scope.showCon=function(){
$scope.tabObj={'foo':['AA','BB']};
$scope.test=Array.isArray($scope.tabObj.foo);
警报(“字段是数组吗?”+$scope.test);
}
}

按钮1
{{tabObj.foo}}

isArray(tabObj.foo)
没有调用任何东西,您是否缺少控制器中的
$scope.isArray=function(arr){return Array.isArray(arr);}
?@Aleksey-所以我不能在
ng show
中使用
Array.isArray()
函数?(就像这里)大多数
ng-
属性都假定您的函数/变量被绑定到
$scope
,但是
$scope.isArray
$scope.Array.isArray
在控制器中不可用
isArray(tabObj.foo)
没有调用任何东西,您是否缺少
$scope.isArray=函数(arr){return Array.isArray(arr);}
在控制器中?@Aleksey-所以我不能在
ng show
内部使用
Array.isArray()
函数?(像这里)大多数
ng-
属性都假定您的函数/变量被限制在
$scope
范围内,但
$scope.isArray
$scope.Array.isArray
在控制器中不可用,因此我无法在
ng show
内部使用
角度.isArray
函数?(如此处)所以我不能在
ng show
内部使用
angular.isArray
函数(如此处)
<div ng-app>
  <div ng-controller="showCrtl">
        <button class="" ng-click="showCon()">Button1</button>   
        <select ng-show="isArray(tabObj.foo)" ng-model="tabObj.foo" ng-options="x for x in tabObj.foo"></select>
        <span ng-if="!isArray(tabObj.foo)">{{tabObj.foo}}</span>
    </div>
</div>
function showCrtl($scope){
    $scope.showCon=function(){
        $scope.tabObj={'foo':['AA','BB']};
        alert("is field is Array? "+Array.isArray($scope.tabObj.foo));
    }
}
function showCrtl($scope){
    $scope.showCon=function(){
        $scope.tabObj={'foo':['AA','BB']};
        $scope.isArray = angular.isArray;
        alert("is field is Array? "+Array.isArray($scope.tabObj.foo));
    }
}