我在Angular中有这个对象。
$scope.columns = {
workspace: {
title: "Workspace",
type: "workspace",
activities: []
},
alerts: {
title: "Alerts",
type: "alert",
activities: []
},
main: {
title: "Main Feed",
type: "main",
activities: []
}
};
我需要在HTML中循环遍历它,以动态创建我的应用程序中的一系列列(类似Trello)。
每个type
都是一个自定义指令的引用。
我正在尝试找出放置指令的最佳方式。
基于这些数据,下面的代码是否是处理动态创建它们的适当方式?
<div ng-repeat="(key, obj) in columns">
<div ng-switch on="obj.type">
<workspace-feed ng-switch-when="workspace" />
<alert-feed ng-switch-when="alert" />
<main-feed ng-switch-when="main" />
<filter-feed ng-switch-when="filter" />
</div>
</div>
我很乐意能够做出类似于...
<{{obj.type}}-feed />
的东西,但我不确定这是否有效,或者是否有更好的方法来创建它。非常感谢您的想法!