Reputation: 169
I need to create a web app that can handle different template (same class but with addition field/functions). I use AngularJS.
For all the css side, I use SASS. For the HTML part, I use ng-include of AngularJS. But I don't know what to use for the JS part. I could have the same js file for each template with all the changes but if there a change I would need to change all the files. What I look for is a framework/tool that allow me to have a base js file and load inside extra content from other file (like ng-include in AngularJS).
Thanks in advance
Upvotes: 2
Views: 52
Reputation: 2150
I think that you a looking for ngRoute
or ui-router
. They are components that let you create routes in you application. It means that you can define one route that contains a HTML file and a Controller associated.
Take a look at the documentation of the two.
This is an example using ngRoute: https://jsfiddle.net/relferreira/t36xa01c/
HTML:
<div data-ng-app="app">
<ul class="nav navbar-nav" id="subject">
<li><a href="#/">Main</a></li>
<li><a href="#/detail">Detail</a></li>
</ul>
<div ng-view></div>
</div>
JS:
angular.module('app', ['ngRoute']);
angular.module('app')
.config(config)
.controller('MainController', mainController)
.controller('DetailController', detailController);
config.$inject = ['$routeProvider'];
function config($routeProvider){
$routeProvider.when('/',{
template:'<h1>{{mainVm.title}}</h1>',
controller: 'MainController as mainVm'
})
.when('/detail',{
template:'<h1>{{detailVm.title}}</h1>',
controller: 'DetailController as detailVm'
})
.otherwise({
redirectTo:"/"
});
}
mainController.$inject = ['$scope'];
function mainController($scope){
var vm = this;
vm.title = 'Main'
}
detailController.$inject = ['$scope'];
function detailController($scope){
var vm = this;
vm.title = 'Detail'
}
Upvotes: 1