codenamezjames / angular-static-include

Angular directive to include files "staticly" E.G. without creating a new child scope. thanks to this SO question http://stackoverflow.com/questions/12393703/how-to-include-one-partials-into-other-without-creating-a-new-scope
MIT License
12 stars 3 forks source link

Angular directives not working inside included template #2

Open diimpp opened 9 years ago

diimpp commented 9 years ago

I've ng-model and they are not evaluated.

This fixes that.

- $compile(contents)($scope.$parent);
+ $compile(contents)($scope);

angular 1.2.28

codenamezjames commented 9 years ago

But compiling on the child scope would defeated the purpose of the directive. if you want the child scope you could just use the regular ng-include. Right?

diimpp commented 9 years ago

That sounds right, but is it what happens? Directive don't have its own scope, therefore it's adds it to current scope?

I've just recheck with static-include with my fix, without and with ng-include. I've ui-router state with simple controller, that maps to form. For example

$scope.user = {};

And two view htmls, index.html and _form.html, where first one includes _form.html and _form.html contains inputs with ng-model to $scope.user properties

     <div class="form-group" show-errors>
         <label class="col-sm-2" for="name" translate="user.create.name"></label>
         <div class="col-sm-10">
             <input id="name"
                    name="name"
                    type="text"
                    class="form-control"
                    ng-model="user.name"
                    ng-minLength="4"
                    ng-maxLength="64"
                    ng-required="true" />
         </div>
     </div>

So

  1. Works
  2. Doesn't, active scope is not the same, as in controller.
  3. Fails with some obscure form validation errors (Just my setup issue, won't work anyway)