[Templates] Use templateLinker for forms

...for compatibility with both template and templateUrl
This commit is contained in:
Victor Woeltjen 2016-02-26 15:01:40 -08:00
parent 8581547a9c
commit 5c3d8508a2
3 changed files with 8 additions and 22 deletions

View File

@ -77,6 +77,7 @@ define([
"key": "mctControl",
"implementation": MCTControl,
"depends": [
"templateLinker",
"controls[]"
]
}

View File

@ -36,23 +36,18 @@ define(
* @constructor
* @memberof platform/forms
*/
function MCTControl(controls) {
function MCTControl(templateLinker, controls) {
var controlMap = {};
// Prepopulate controlMap for easy look up by key
controls.forEach(function (control) {
var path = [
control.bundle.path,
control.bundle.resources,
control.templateUrl
].join("/");
controlMap[control.key] = path;
controlMap[control.key] = control;
});
function link(scope, element, attrs, ngModelController) {
var changeTemplate = templateLinker.link(scope, element);
scope.$watch("key", function (key) {
// Pass the template URL to ng-include via scope.
scope.inclusion = controlMap[key];
changeTemplate(controlMap[key]);
});
scope.ngModelController = ngModelController;
}
@ -61,10 +56,6 @@ define(
// Only show at the element level
restrict: "E",
// Use ng-include as a template; "inclusion" will be the real
// template path
template: '<ng-include src="inclusion"></ng-include>',
// ngOptions is terminal, so we need to be higher priority
priority: 1000,

View File

@ -27,8 +27,8 @@
* @namespace platform/forms
*/
define(
["./controllers/FormController"],
function (FormController) {
["./controllers/FormController", "text!../res/templates/form.html"],
function (FormController, formTemplate) {
"use strict";
/**
@ -52,18 +52,12 @@ define(
* @constructor
*/
function MCTForm() {
var templatePath = [
"platform/forms", //MCTForm.bundle.path,
"res", //MCTForm.bundle.resources,
"templates/form.html"
].join("/");
return {
// Only show at the element level
restrict: "E",
// Load the forms template
templateUrl: templatePath,
template: formTemplate,
// Use FormController to populate/respond to changes in scope
controller: [ '$scope', FormController ],