[Forms] Add mct-control directive

Add an mct-control directive which can represent
individual form controls. WTD-530.
This commit is contained in:
Victor Woeltjen 2014-11-26 08:43:41 -08:00
parent 695ca5c0cf
commit 9576673b84

View File

@ -0,0 +1,49 @@
/*global define*/
define(
[],
function () {
"use strict";
function MCTControl(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;
});
function controller($scope) {
$scope.$watch("key", function (key) {
// Pass the template URL to ng-include via scope.
$scope.inclusion = controlMap[$scope.key];
});
}
return {
// Only show at the element level
restrict: "E",
// Use the included controller to populate scope
controller: controller,
// Use ng-include as a template; "inclusion" will be the real
// template path
template: '<ng-include src="inclusion"></ng-include>',
// Pass through Angular's normal input field attributes
scope: {
ngModel: "=",
ngOptions: "=",
ngDisabled: "=",
ngPattern: "="
}
};
}
}
);