0

I have a list of HTML widgets which are created dynamically from server data like this (Jade):

.area(ng-repeat="widget in widgetsList.widgets")
    h3 {{widget.title}}
    p {{widget.type}}
    span {{widget.data}}

Widgets are not of the same structure and I don't want to show them visually equal because each of them represents its own functionality. The paragraph in the end of the example just puts data json as a string that I obviously need to render as a proper html widget according to its type that looks like 'important-messages-widget' or 'recent-events-widget'.

Angular looks pretty good but lacks of detailed documentation. How should I manage this case?

4

1 回答 1

0

在 Angular 中,有两个内置指令真正让 Angular 变得强大。

  1. ng-repeat(您已经在使用)

  2. ng-switch 这似乎最常被大多数开发人员误解或不理解或类似的东西。它为您提供了在 html 中使用普通编程语言的 switch 语句的强大功能。

http://docs.angularjs.org/api/ng.directive:ngSwitch

它的文档应该为您提供一个很好的起点。结合 ngSwitch 和 ng-repeat 会给你一种非常强大的方式来表示你的视图。

<div ng-switch on="widget.type" >
    <div ng-switch-when="important-messages-widget">Important Message</div>
    <div ng-switch-when="recent-events-widget">Recent Events ---add more html here </div>
</div>

希望这可以帮助。

于 2012-08-31T09:20:58.907 回答