Permalink
Browse files

Fixed the compiling bug thanks to @ajoslin

  • Loading branch information...
1 parent 2912b8f commit ae88061b680cee9f213629a00a4ef24344041642 Dean Sofer committed Nov 1, 2012
Showing with 41 additions and 16 deletions.
  1. +41 −16 modules/directives/input/input.js
@@ -1,3 +1,23 @@
+/*
+Test HTML
+
+
+ <section id="directives-input">
+ <div class="page-header">
+ <h1>Input</h1>
+ </div>
+ <div class="well">
+ <script type="text/ng-template" id="input">
+ <pre>{{$input.model|json}}</pre>
+ <input ng-transclude id="{{$input.id}}">
+ <label for="{{$input.id}}">{{$input.label}}</label>
+ </script>
+ <pre>Model: {{input|json}}</pre>
+ <ui-input src="'input'" label="Input" required ng-model="$parent.input"></ui-input>
+ </div>
+ </section>
+
+ */
angular.module('ui.directives')
.directive('uiInput', ['$compile', '$http', '$templateCache', 'ui.config', function ($compile, $http, $templateCache, uiConfig) {
@@ -51,30 +71,35 @@ angular.module('ui.directives')
compile:function compile(tElement, tAttrs, transclude, uiForm) {
var model = tAttrs.ngModel, input = {
- id:tAttrs.id || 'input' + nextUid(idUid)
+ id:tAttrs.id || 'id' + nextUid(idUid)
};
return function (scope, element, attrs) {
- //infer a field type from template's tag name (can be one of ui-input, ui-select, ui-textarea)
- $http.get(scope.$eval(attrs.src), {cache:$templateCache}).success(function (response) {
+ scope.$watch(attrs.src, function(newVal, oldVal) {
+ if (!newVal)
+ return;
+ $http.get(newVal, {cache:$templateCache}).success(function (response) {
- element.html(response);
+ element.html(response);
- var inputEl = element.find('[ng-transclude]');
- angular.forEach(tAttrs, function (value, key) {
- if (key.charAt(0) !== '$' && ['src','uiInput'].indexOf(key) === -1) {
- inputEl.attr(snake_case(key, '-'), value);
- }
- });
+ var inputEl = element.find('[ng-transclude]');
+ angular.forEach(tAttrs, function (value, key) {
+ if (key.charAt(0) !== '$' && ['src','uiInput', 'id'].indexOf(key) === -1) {
+ inputEl.attr(snake_case(key, '-'), value);
+ input[key] = value;
+ }
+ });
+ inputEl.removeAttr('ng-transclude');
- //prepare validation messages
- input.validation = angular.extend({}, uiConfig.input.validation, scope.$eval(tAttrs.validation));
+ //prepare validation messages
+ input.validation = angular.extend({}, uiConfig.input.validation, scope.$eval(tAttrs.validation));
- //expose model to a field's template
- scope.$input = input;
- $compile(element.contents())(scope);
- scope.$field = inputEl.controller('ngModel');
+ //expose model to a field's template
+ scope.$input = input;
+ $compile(element.contents())(scope);
+ scope.$field = inputEl.controller('ngModel');
+ });
});
};
}

0 comments on commit ae88061

Please sign in to comment.