在 angularjs ng-switch 子范围表单不可用在父范围不可用
in angularjs ng-switch child scope form is not available not be available on the parent scope
访问写在ng-switch
中的AT模型对象,这里ng-switch
创建了一个子作用域,表单是在这个作用域上创建的。因此,子作用域表单在父作用域中不可用。
请帮忙
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="">
<input type="radio" ng-model="fileType" value="Excel" style=" margin-left: 19px;" >Excel
<input type="radio" ng-model="fileType" value="Text" style=" margin-left: 19px;" >Text
<div ng-switch="fileType">
<div ng-switch-default="Excel">
<h4 style="margin-top: 15px;">
<b>Analysis Type </b>
<input type="radio" ng-model="AT" value="SRI" style=" margin-left: 8px;" >SRI
<input type="radio" ng-model="AT" value="JAG" style=" margin-left: 23px;" >JAG
</h4>
<!-- {{AT}} i am able to acess it -->
</div>
<div ng-switch-when="Text">
<h4 style="margin-top: 15px;"></h4>
</div>
</div>
{{fileType}}
{{AT}} <!-- how can i access it -->
</body>
</html>
这是一个范围继承问题,因为 ng-switch 创建了自己的范围。
在 ng-switch
块中使用 ng-model="$parent.AT"
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="">
<input type="radio" ng-model="fileType" value="Excel" style=" margin-left: 19px;" >Excel
<input type="radio" ng-model="fileType" value="Text" style=" margin-left: 19px;" >Text
<div ng-switch="fileType">
<div ng-switch-default="Excel">
<h4 style="margin-top: 15px;"><b>Analysis Type </b>
<input type="radio" id="atype_sri" ng-model="$parent.AT" value="SRI" style=" margin-left: 8px;" ><label for="atype_sri">SRI</lable>
<input type="radio" id="atype_jag" ng-model="$parent.AT" value="JAG" style=" margin-left: 23px;" ><label for="atype_jag">JAG</label></h4>
</div>
<div ng-switch-when="Text">
<h4 style="margin-top: 15px;"> </h4>
</div>
</div>
{{fileType}}
{{AT}} <!-- now you can access it -->
</body>
</html>
访问写在ng-switch
中的AT模型对象,这里ng-switch
创建了一个子作用域,表单是在这个作用域上创建的。因此,子作用域表单在父作用域中不可用。
请帮忙
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="">
<input type="radio" ng-model="fileType" value="Excel" style=" margin-left: 19px;" >Excel
<input type="radio" ng-model="fileType" value="Text" style=" margin-left: 19px;" >Text
<div ng-switch="fileType">
<div ng-switch-default="Excel">
<h4 style="margin-top: 15px;">
<b>Analysis Type </b>
<input type="radio" ng-model="AT" value="SRI" style=" margin-left: 8px;" >SRI
<input type="radio" ng-model="AT" value="JAG" style=" margin-left: 23px;" >JAG
</h4>
<!-- {{AT}} i am able to acess it -->
</div>
<div ng-switch-when="Text">
<h4 style="margin-top: 15px;"></h4>
</div>
</div>
{{fileType}}
{{AT}} <!-- how can i access it -->
</body>
</html>
这是一个范围继承问题,因为 ng-switch 创建了自己的范围。
在 ng-switch
块中使用 ng-model="$parent.AT"
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="">
<input type="radio" ng-model="fileType" value="Excel" style=" margin-left: 19px;" >Excel
<input type="radio" ng-model="fileType" value="Text" style=" margin-left: 19px;" >Text
<div ng-switch="fileType">
<div ng-switch-default="Excel">
<h4 style="margin-top: 15px;"><b>Analysis Type </b>
<input type="radio" id="atype_sri" ng-model="$parent.AT" value="SRI" style=" margin-left: 8px;" ><label for="atype_sri">SRI</lable>
<input type="radio" id="atype_jag" ng-model="$parent.AT" value="JAG" style=" margin-left: 23px;" ><label for="atype_jag">JAG</label></h4>
</div>
<div ng-switch-when="Text">
<h4 style="margin-top: 15px;"> </h4>
</div>
</div>
{{fileType}}
{{AT}} <!-- now you can access it -->
</body>
</html>