It works for me now. Below is an approach that works for me to add the Angular Controller + template to the Meteor package in the containing application.
In my .js package i have this
Package.onUse(function(api) { api.versionsFrom('1.1.0.3'); api.use('angular: angular@1.4.4 ', 'client'); api.use("urigo: angular@0.9.3 ", 'client'); api.use(" session@1.1.0 ", 'client'); //api.use('angularui: angular-ui-router@0.2.15 ', 'client'); api.addFiles('interests.js', 'client'); api.addFiles('interests.ng.html', 'client'); api.export("InterestsCtrl", "client") });
Please note that you must export your controller so that the parent application can access it.
In my package called ramshackle: bigd-interest , I have these files at the root level: package.js , interests .ng.html and interests .js . interest.js embeds the Angular controller, the Anguilar UI route in the template, and the sidebar link in the parent application. This is achieved through a meteor session. I played with other ways, but the session was the only one that worked. Just be careful to use session variable names correctly.
//add controllers var controllers = Session.get("BIGD.controllers"); if (!controllers) controllers = {}; var interestsCtrlSpec = "'$scope', InterestsCtrl"; InterestsCtrl = function($scope){ console.log("InterestsCtrl running"); }; controllers.InterestsCtrl = interestsCtrlSpec; Session.set("BIGD.controllers", controllers); //add routes var routes = Session.get("BIGD.routes"); if (!routes) routes = {}; routes.interests = { url: '/interests', templateUrl: 'ramshackle_bigd-interests_interests.ng.html', controller: 'InterestsCtrl' }; Session.set("BIGD.routes", routes); //add sidebar links //the key determines sorting order var sidebar = Session.get("BIGD.sidebar"); if (!sidebar) sidebar = {}; sidebar["interests"] = { url: '/interests', templateUrl: 'ramshackle_bigd-interests_interests.ng.html', controller: 'InterestsCtrl', rank: 5 }; Session.set("BIGD.sidebar", sidebar); var interestsItem = {label: 'Interests', link: '/interests', icon: "rocket"};
In my parent app.js application , I dynamically loaded controllers and routes from the session as follows:
angular.module('bigdam',[ 'angular-meteor', 'ui.router', 'angularify.semantic.sidebar', 'nvd3', 'leaflet-directive', 'ui.router.history' ]) .config(['$urlRouterProvider', '$stateProvider', '$locationProvider', function($urlRouterProvider, $stateProvider, $locationProvider){ //console.log("app.js config!"); $locationProvider.html5Mode(true); //add a static state $stateProvider .state('home', { url: '/', templateUrl: 'client/views/home/home.ng.html', controller: 'HomeCtrl' }); //add the dynamic routes/states from other Meteor packages for (var stateId in routes) { var route = routes[stateId]; $stateProvider .state(stateId, route); } $urlRouterProvider.otherwise('/'); }]) ; //Declare the controllers from plugins for (var controllerId in controllers) { var controllerSpec = controllers[controllerId]; var controllerSpecArray = eval("[" + controllerSpec + "]") angular.module('bigdam').controller(controllerId, controllerSpecArray); }
So now, when I create a new Meteor package and follow the agreement described above, its controllers, routes and sidebar links are loaded into the main application.