When I create a new element through a line that has a directive (so I need to compile), and this directive generates a connection to a variable in the controller area via "=", the variable in my controller is not related to the one specified in the directive.
I created jsfiddle to show an example where the value of the door ng model should be associated with all the values ββof the directives.
See this script: http://jsfiddle.net/aVJqU/2/
Another thing that I notice is that the directive, which is executed from the elements present in the html, shows the correct connection through variables (controller and directive).
html (there is a directive that binds <door> ):
<body ng-app="animateApp"> <div ng-controller="tst"> <h2> Controller with its model </h2> <input ng-model="doorval" type="text"> </input> {{doorval}} <h2> Directive render directly from the html </h2> <door doorvalue="doorval"></door> <key></key> <h2> Directives that are compiled </h2> <list-actions actions="actions"></list-actions> </div> </body>
This is the directive:
animateAppModule.directive('door', function () { return { restrict: "E", scope: { doorvalue:"=" }, template: '<span>Open the door <input type="text" ng-model="doorvalue"> </input> {{doorvalue}}</span>', replace: true } })
This is the controller:
var animateAppModule = angular.module('animateApp', []) animateAppModule.controller('tst', function ($scope, tmplService) { $scope.doorval = "open" $scope.actions = tmplService; }) animateAppModule.service('tmplService', function () { return [{ form_layout: '<door doorvalue="doorval"></door> <key></key>' }, { form_layout: '<door doorvalue="doorval"></door> with this <key></key>' }] })
And finally, this is a directive that compiles a line with a directive that does not bind:
animateAppModule.directive('listActions', function ($compile) { return { restrict: "E", replace: true, template: '<ul></ul>', scope: { actions: '=' }, link: function (scope, iElement, iAttrs) { scope.$watch('actions', function (neww, old,scope) { var _actions = scope.actions; for (var i = 0; i < _actions.length; i++) {
What can I do to bind all the ng-model door values ββtogether? Where is the compiled directory binding to?