AngularJS directive as components

I am in a project where we want to componentify a lot of “information boxes”.
These boxes (lets say they are mostly different types of tables) should easily be included into different pages and even different projects(we include the components as a library into an angular js project, so angular js a requirement). In the long run these components might even be available as an API for other developers to use.

So far the directives include their own template, a common css styling + a unique style for the component, a set of testdata files.

So my question is basically: can this be a good approach? Is it faulty to make the directives actually load the data themselves or should I always pass the data to them?
The reason I want the directive to load data themselves is that I include testdata in the library allowing for testing the components in place (on for instance a dashboard) without having to implement the “real” data.

Also, the components will have at least three states (loading, faulty data, finished loading) which I think should lie with the directive, again prompting for the directive to load the data itself.

My thought was to either pass (for testing):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><my-directive test-data="testfile.json">
<my-directive load-data="/myurl">
</code>
<code><my-directive test-data="testfile.json"> <my-directive load-data="/myurl"> </code>
<my-directive test-data="testfile.json">
<my-directive load-data="/myurl">

Is this a good approach. If yes, should I put the data loading in the directive controller and utilizing some common “data-fetching-service” for all components?

I understand that this “question” is more a ramble than anything else but it’s really hard to make a design decision which such limited angularjs knowledge, so I am reaching out!

So far the directives include their own template, a common css styling + a unique style for the component, a set of testdata files.

So my question is basically: can this be a good approach?

If your directives are variations of visualization, but keep the same functionality, I recommend you to have only one main directive and create inner directives that allow the developer to customize how it’ll look.

A good example of this includes Angular UI Bootstrap Tabs.

Is it faulty to make the directives actually load the data themselves or should I always pass the data to them?

Directives are pieces of reusable components. If you embed the data loading into the directive, your controllers will be simpler.

But what if there’s a need to filter that data in just an specific part of your application? Let the developer pass the data they want, either filtered or not.

The reason I want the directive to load data themselves is that I include testdata in the library allowing for testing the components in place (on for instance a dashboard) without having to implement the “real” data.

A good approach would be to create a myComponentTestData service, which allow you to decide from the controller what to use, and then pass that data to your directive.

Also, the components will have at least three states (loading, faulty data, finished loading) which I think should lie with the directive, again prompting for the directive to load the data itself.

You’re right in thinking that the state should lie in the directive. You can control this behavior by passing a promise instead of the fetched data — if the promise is fulfilled, then you test if your data is faulty or not.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật