我正在动态创建文本框,因此我还需要动态模型名称,我想我应该使用它的Id,因为它是相同的。
我有这个文本框:
<input type="text" ng-init="scope[child.Root.Id] = ''" ng-model="scope[child.Root.Id]" />
文本框应绑定到Child.Root.Id的值,这似乎有效,因为以下示例工作得很好:
<p ng-hide="scope[child.Root.Id] == 123">This is a test.</p>
<p ng-hide="scope[child.Root.QuestionModel.ItemId] == 123">This is a test.</p>
这两个Id都具有相同的值。当文本框中输入“123”时,文本会隐藏。
但是,我需要隐藏其他东西,在这个地方我不能使用child.Root.id,但我确实有一个child.Root.ParentId具有相同的值:
<p ng-hide="scope[child.Root.ParentId] == 123">This is also a Test!</p>
这不起作用,我做错了什么?
这是我在Angular的第一个项目,所以我没有多少经验。
提前致谢。
编辑:
<div ng-app="myApp" ng-controller="ctrl">
@*Start myApp-html-html*@
<script type="text/ng-template" id="field_renderer.html">
<!-- Group-->
<div ng-if="child.Root.GroupModel!=null">
<div ng-bind="child.Root.GroupModel.Header"></div>
<div ng-repeat="child in child.Children" ng-include="'field_renderer.html'"></div>
</div>
<!-- Question-->
<div class="Question" ng-if="child.Root.QuestionModel!=null" >
@Html.Partial("QuestionEntryPartialView")
<div ng-repeat="child in child.Children" ng-include="'field_renderer.html'"></div>
</div>
<!-- Decission-->
<div ng-if="child.Root.DecisionModel!=null">
<p ng-hide="scope[child.Root.ParentId] == 123">This is also a test!</p>
@*<div ng-repeat="child in child.Children" ng-include="'field_renderer.html'"></div>*@
</div>
</script>
<span ng-repeat="child in model.Children" ng-include="'field_renderer.html'">
<span ng-if="child.Root.GroupModel!=null" ng-bind=" child.root.groupmodel.header"></span>
<span ng-if="child.Root.QuestionModel!=null" ng-bind="child.Root.QuestionModel.Question"></span>
<span ng-if="child.Root.DecisionModel!=null" ng-bind-html="child.Root.DecisionModel.Description"></span>
</span>
@*End myApp*@
</div>
<script>
var app = angular.module('myApp', []);
app.controller('ctrl', function ($scope, $http, $sce) {
window.MY_SCOPE = $scope;
$http.post('@Url.Action("GetItemsModel", "Question")')
.success(function (response) {
$scope.model = response;
console.log(response);
});
});
</script>
QuestionEntrypartialView包含:
<div>
<input type="text" ng-init="scope[child.Root.Id] = ''" ng-model="scope[child.Root.Id]"/>
</div>
<p ng-hide="scope[child.Root.Id] == 123">This is a test.</p>
<p ng-hide="scope[child.Root.QuestionModel.ItemId] == 123">This is a test.</p>