Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Angularjs 简单ng show isn';行不通_Angularjs - Fatal编程技术网

Angularjs 简单ng show isn';行不通

Angularjs 简单ng show isn';行不通,angularjs,Angularjs,选择其他值时,我的简单ng显示不起作用div应隐藏 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example - example-radio-input-directive-production</title> <script src="//ajax.googleapis.com/ajax/libs/ang

选择其他值时,我的简单ng显示不起作用div应隐藏

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example - example-radio-input-directive-production</title>


  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.min.js"></script>



</head>
<body ng-app="">
   <script>
   function Ctrl($scope) {
     $scope.color = 'blue';
     $scope.specialValue = {
       "id": "12345",
       "value": "green"
     };
   }
 </script>
 <form name="myForm" ng-controller="Ctrl">
   <input type="radio" ng-model="color" value="red">  Red <br/>
   <input type="radio" ng-model="color" ng-value="specialValue"> Green <br/>
   <input type="radio" ng-model="color" value="blue"> Blue <br/>
   <tt>color = {{color | json}}</tt><br/>
  </form>
  Note that `ng-value="specialValue"` sets radio item's value to be the value of `$scope.specialValue`.
  <div ng-show="color==blue">some test</div>
</body>
</html>

示例-示例无线电输入指令生成
函数Ctrl($scope){
$scope.color='blue';
$scope.specialValue={
“id”:“12345”,
“值”:“绿色”
};
}
红色
绿色
蓝色
颜色={{color | json}}
注意,`ng value=“specialValue”`将单选项的值设置为“$scope.specialValue”的值。 一些测试

这里是

你必须这样写,因为蓝色是一个字符串:

ng-show="color == 'blue'"

您的ng秀不在控制器的范围内

这样做:

<div ng-controller="Ctrl">
  <form name="myForm">
    <input type="radio" ng-model="color" value="red">  Red <br/>
    <input type="radio" ng-model="color" ng-value="specialValue"> Green <br/>
    <input type="radio" ng-model="color" value="blue"> Blue <br/>
    <tt>color = {{color | json}}</tt><br/>
  </form>
  <div ng-show="color=='blue'">some test</div>
</div>

红色
绿色
蓝色
颜色={{color | json}}
一些测试
您的ng show不在控制器范围内,请尝试使用“body ngApp=”“”而不是“body ng app=”“”

现在发布我的答案似乎为时已晚,但下面是上面的一个例子: