1

I have directive in my Angular code. It has isolated scope binded to attributes of element; changing model controller; postlink function designed to bind click callbacks to elements in template; template with ng-switch.

    scope: {
        payload: '='
    },
    controller: function($scope){
        $scope.havePayload = $scope.payload;
    },
    link: {
        post: function(scope, elem, attrs){
             elem.children(".with-payload").css( "background-color", "red" );   
        }
    },
    restrict: 'A',
    replace: true,
    template: '<div ng-switch on="havePayload"> \
                    <div ng-switch-when="true" class="with-payload"></div> \
                    <div ng-switch-when="false" class="without-payload"></div> \
                </div>'

The problem is that when postlink starts, ng-switch still doesn't know anything about model and doesn't include in DOM elements that I need in postlink. It's strange, because postlink should be executed only when template is agreed with model.
Here is jsfiddle example. Looks strange, I know. Just my poor fantasy :)
Update
(http://jsfiddle.net/NXQ8G/3/) Doesn't seem to work.

mkrakhin
  • 3,386
  • 1
  • 21
  • 34
  • you should compile it http://stackoverflow.com/questions/21804311/how-to-set-ng-disabled-inside-directive/21804745#21804745 – Whisher Feb 18 '14 at 13:12
  • Maybe I'm doing something wrong. Please, check update. – mkrakhin Feb 18 '14 at 13:29
  • Btw, if we'll use terminal, then ng-switch would be executed before controller. What I want is: controller -> execution of directives in template -> post linking. – mkrakhin Feb 18 '14 at 14:16

0 Answers0