I am diving head first into Angular 1 for the first time with an existing app. One of the things about this app that I want to change is how there are separate services and other things for every entity in our application.
I've abstracted it out so that there's only one service for all entities, but now I am trying to load a template where the file name is equal to a particular state parameter.
Here's how the per-entity routing is done now:
namespace App.Employee {
'use strict';
angular
.module('app.employee')
.run(appRun);
appRun.$inject = ['routerHelper'];
function appRun(routerHelper: Common.Router.IRouterHelperService) {
routerHelper.configureStates(getStates());
}
function getStates() {
return [{
name: 'employee',
url: '/employee/{employeeId}',
templateUrl: 'app/employee/employee.html',
controller: 'employeeCtrl',
controllerAs: 'vm',
data: {
title: 'Employee'
}
}];
}
}
Here's what I want to change it to:
namespace App.Entity {
'use strict';
angular
.module('app.entity')
.run(appRun);
appRun.$inject = ['routerHelper'];
function appRun(routerHelper: Common.Router.IRouterHelperService) {
routerHelper.configureStates(getStates());
}
function getStates() {
return [{
name: '||entityTypeName||',
url: '/{entityTypeName}/{entityId}',
templateUrl: 'app/entity/||entityTypeName||.html',
controller: 'entityCtrl',
controllerAs: 'vm',
data: {
title: '||entityTypeName||'
}
}];
}
}
Notice how I introduced {entityTypeName}
in the URL. This successfully points to the proper Web API service and pulls back the entity. However, I want to tokenize the ||entityTypeName||
placeholder to be what's matched for {entityTypeName}
. That's the general idea, at least.
I know little of Angular at this point and am learning as I go along, so let me know if additional code is needed.