我的简单ng-show isn工作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>
这里是link
答案 0 :(得分:3)
您的ng-show超出了控制器的范围。
这样做:
<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>
答案 1 :(得分:1)
你必须这样写,因为蓝色是一个字符串:
ng-show="color == 'blue'"
答案 2 :(得分:-1)
你的ng-show超出了控制器范围,并尝试使用'body ngApp =“”'代替'body ng-app =“”'