-
Notifications
You must be signed in to change notification settings - Fork 0
Cookbook: Angular UI Router Templates
Regardless of markup type (e.x.: Jade or HTML), templates are stored in Angular's $templateCache. Rupert intelligently stores the template as based off of the template's relative 'feature' directory name via a <dir>/<component name>-template.<ext> format.
-
Once Rupert is installed, ensure the Angular toolkit is in place:
npm install --save rupert-config-angular
-
Add the UI Router dependency to
/src/client/main.js(it is built into the Rupert Angular install as the default router/state machine):angular.module('rupert-app', [ 'ui.router' ]);
-
Add the UI Router view directive to
/src/client/index.html(default index is in Jade markup):... <body> <ui-view></ui-view> ...
-
Create a test feature directory (
/src/client/foo) with abar-template.htmltherein:<h1>{{baz}}</h1>
-
Appropriately reference the template in
/src/client/main.js:angular.module('rupert-app', [ 'ui.router', 'foo.bar.template' ]); angular.module('rupert-app') .config(function($stateProvider) { $stateProvider .state('some-state', { url: '/some-state', templateUrl: 'foo/bar', controller: function($scope) { $scope.baz = 'bop'; } }); });
...and route /#/some-state should show text 'bop' in a large font.
Note that this is a trivial example and route declarations/controllers should be broken out into their respective individual files for production.