Angular ui-router: ui-views vs directives?

后端 未结 4 1048
陌清茗
陌清茗 2020-12-12 14:35

The angular ui-router allows multiple nested views. The role of these interchangeable views seems to overlap the role of directives.

What are the pros/cons

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 14:54

    How about if you used Angular UI router's inline views to point to directives?

    Let's say you have a directive for a table that handles CRUD operations on user accounts. We'll say the directive is named user-admin. Our routes file would look like:

    .state('users', {
      url: '/users',
      template: ""
    });
    

    This would give you many nice things:

    • Allow you to have a url that points straight to a directive
    • Removes the duplication of needing two templates (view template and directive template) when a state is just a directive
    • Allow you to start moving more controller logic into directives in prep for Angular 2.0. See here and here.

提交回复
热议问题