简体   繁体   中英

How do I combine two AngularJS apps as modules of a main app?

Another basic AngularJS question. I have two AngularJS apps, slider.js (AngularUI) & json.js .

Here's slider.js as a Plunkr.

Here's json.js as a Plunkr.

I want them both to run on a page. In fact, I want to use them together: I want to render sliders within my JSON renders. What is the best way to do this? This answer suggests creating a Main app & calling these both within it. Is that a good solution for when I want the functionality of both apps in the same place on the page, or should I be working on "combining" the apps- and how would one go about doing that?

My not-working attempt so far is here:

Plunkr of the two apps combined, not working

You need to add the slider as dependent of myapp then use myapp in the page declaration, so that myApp will have all elements(directives/controllers/filters etc) added in slider app also.

var myApp = angular.module('myApp', ['ui.slider']);

then

<html ng-app="myApp">

Demo: Plunker

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM