我不确定我是如何关闭此功能但是我有一个对象在视图中显示我的所有数据,但在控制器中没有引用它。
我认为我的数据位于 $ scope 或此,但不是我能找到的。
这是我的观点:
<script src="controllers/Multiple-Checkboxes.js"></script>
<div ng-controller="tenant.views.surveys.index.display.multiple-checkboxes as vm">
<h6>{{item}}</h6
<h6>{{vm.NumberOfColumns.Value}}</h6>
</div>
很好地输出我想在控制器中使用的所有数据。
这是我的控制者:
(function () {
appModule.controller('tenant.views.surveys.index.display.multiple-checkboxes', [
'$scope', 'abp.services.app.survey',
function ($scope, surveyService) {
var vm = this;
vm.parent = $scope.$parent.$parent.vm;
console.log(this);
console.log($scope);
vm.NumberOfColumns = { Value: 4 };
}
]);
})();
此除了numberOfColumns和parent之外什么都没有。
$ scope 包含
b
$$ChildScope: b()
$$childHead: b
$$childTail: b
$$listenerCount: Object
$$listeners: Object
$$nextSibling: null
$$prevSibling: null
$$watchers: Array[5]
$$watchersCount: 26
$id: 1927
$parent: m
vm: Object
__proto__: m
我确实在这里找到了我的数据:
$$watchers:Array[5]
0:Object
1:Object
2:Object
3:Object
4:Object
eq:false
exp:(c,e,f,g)
fn:(a,c,f)
get:(a)
last: "{"title":"Multi check","body":"Check all that apply","response":{"type":{"type":"Multiple Checkboxes","isDeleted":false,"deleterUserId":null,"deletionTime":null,"lastModificationTime":null,"lastModifierUserId":null,"creationTime":"2016-12- 21T20:01:31.46Z","creatorUserId":null,"id":1},"options":[{"label":"Red","value":"1"},{"label":"Orange","value":"2"},{"label":"Yellow","value":"3"}, {"label":"Green","value":"4"},{"label":"Blue","value":"5"},{"label":"Violet","value":"6"},{"label":"Magenta","value":"7"}],"settings": [],"isDeleted":false,"deleterUserId":null,"deletionTime":null,"lastModificationTime":null,"lastModifierUserId":null,"creationTime":"2016-12- 21T20:11:59.087Z","creatorUserId":null,"id":120},"controlSettings":null,"surveyTypes":["Product Evaluation","Marketing Research","Marketing"],"audiences":["Internal","External"],"valid":true,"tags": [],"isDeleted":false,"deleterUserId":null,"deletionTime":null,"lastModificationTime":null,"lastModifierUserId":null,"creationTime":"2016-12- 21T20:11:59.087Z","creatorUserId":null,"id":120,"list":"survey"}"
但这不可能是访问它的正确位置。
[UPDATE]
这是{{item}}当前显示的内容:
{"title":"Multi check","body":"Check all that apply","response":{"type":{"type":"Multiple Checkboxes","isDeleted":false,"deleterUserId":null,"deletionTime":null,"lastModificationTime":null,"lastModifierUserId":null,"creationTime":"2016-12-21T20:01:31.46Z","creatorUserId":null,"id":1},"options":[{"label":"Red","value":"1"},{"label":"Orange","value":"2"},{"label":"Yellow","value":"3"},{"label":"Green","value":"4"},{"label":"Blue","value":"5"},{"label":"Violet","value":"6"},{"label":"Magenta","value":"7"}],"settings":[],"isDeleted":false,"deleterUserId":null,"deletionTime":null,"lastModificationTime":null,"lastModifierUserId":null,"creationTime":"2016-12-21T20:11:59.087Z","creatorUserId":null,"id":120},"controlSettings":null,"surveyTypes":["Product Evaluation","Marketing Research","Marketing"],"audiences":["Internal","External"],"valid":true,"tags":[],"isDeleted":false,"deleterUserId":null,"deletionTime":null,"lastModificationTime":null,"lastModifierUserId":null,"creationTime":"2016-12-21T20:11:59.087Z","creatorUserId":null,"id":120,"list":"survey"}
我希望在我的控制器中访问它。
答案 0 :(得分:0)
您使用的是controller as vm
语法,item
没有vm.
的前缀,我怀疑item
对象是在父级或兄弟级范围内。< / p>
我们需要查看更多代码(主要是HTML)以帮助您进一步。
答案 1 :(得分:0)
视图中的{{item}}确实由父$ scope填充。
这是一个子控制器。要访问父$ scope,我使用了
var vm = this;
vm.parent = $scope.$parent;
vm.item = vm.parent.item;
然后,在视图中,将{{item}}切换为{{vm.item}}
有一些关于没有混合vm和$ scope 的智慧,这通常在这个聊天中概述:http://chat.stackoverflow.com/transcript/131207但也许是另一个线程。
(除非@Claies想加入。)