view - Setting templateUrl in an AngularJS Module to increase modularity -
i have nested angularjs modules eventlist
, eventpage
.
the directory structure looks this:
app.js eventform |_ eventlist.js eventlistview.html eventpage |_eventpage.js eventpageview.html
eventlist.js:
angular.module('eventlist', ['eventpage']) .config([ '$routeprovider', function config($routeprovider){ $routeprovider.when(urls.event_list, { templateurl: 'app/eventlist/event-list.html', controller: 'eventlistctrl' }); }]) .controller('eventlistctrl', ['$scope', '$location', '$http', function eventlistcontroller($scope, $location, $http) { }]);
eventpage.js:
angular.module('eventpage', []) .config([ '$routeprovider', function config($routeprovider){ $routeprovider.when(urls.event_page + '/:id', { templateurl: 'app/eventlist/eventpage/event-page.html', controller: 'eventpagectrl' }) }]) .controller('eventpagectrl', ['$scope', '$routeparams', '$http', function eventpagecontroller($scope, $routeparams, $http) { }]);
obviously templateurl
hardcoded right now. question best way set templateurl
in routeprovider modules aren't dependent on hard coded directory structure , can taken out , reused in other angularjs projects without breaking? there way insertviewnamehere.html
in current folder?
if you're using grunt, easy. not because modularizing angularjs trivial, because hard work has been done folk doing angular-bootstrap...
when faced problem downloaded gruntfile , changed every ui.bootstrap
my-angular-module
. since mimicked basic directory structure, worked right out of box.
also, might want update angular , bootstrap versions. e.g., change
ngversion: '1.0.8', bsversion: '2.3.1',
to
ngversion: '1.2.3', bsversion: '3.0.2',
Comments
Post a Comment