From 5c3d8508a22466fd4094dcda2c9295fbc0e9a2d2 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 26 Feb 2016 15:01:40 -0800 Subject: [PATCH] [Templates] Use templateLinker for forms ...for compatibility with both template and templateUrl --- platform/forms/bundle.js | 1 + platform/forms/src/MCTControl.js | 17 ++++------------- platform/forms/src/MCTForm.js | 12 +++--------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/platform/forms/bundle.js b/platform/forms/bundle.js index 5cd3cbdaad..19ebf4d9b5 100644 --- a/platform/forms/bundle.js +++ b/platform/forms/bundle.js @@ -77,6 +77,7 @@ define([ "key": "mctControl", "implementation": MCTControl, "depends": [ + "templateLinker", "controls[]" ] } diff --git a/platform/forms/src/MCTControl.js b/platform/forms/src/MCTControl.js index 78ac8c194d..09192a09ee 100644 --- a/platform/forms/src/MCTControl.js +++ b/platform/forms/src/MCTControl.js @@ -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: '', - // ngOptions is terminal, so we need to be higher priority priority: 1000, diff --git a/platform/forms/src/MCTForm.js b/platform/forms/src/MCTForm.js index ce48ed1572..70c18cbf2f 100644 --- a/platform/forms/src/MCTForm.js +++ b/platform/forms/src/MCTForm.js @@ -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 ],