I have a directive that based on a few attributes, would calculate a URL
and pass that into ngInclude.  My issue is that the templates that get
included are dependent on variables set in parent scopes.  The directive
that I wrote to calculate the template url for the ngInclude uses an
isolate scope.  I believe this is making the parent scope variables needed
by the included template unavailable.

Here is what my directive looks like, changed names, apologize for typos:

angular.module('abc').directive('myInclude', function() {
  return {
    restrict: 'E',
    scope: {
      myType: '=',
      myIncludeId: '@'
    },
    replace: true,
    template: "<div ng-include='myIncludeUrl''></div>",
    controller: function($scope, myService) {
      function _calculateUrl() {

        $scope.myIncludeUrl = myService.createCustomUrl($scope.myIncludeId,
$scope.myType);
      };

      $scope.$watch('myType', _calculateUrl);
      $scope.$watch('myIncludeId', _calculateUrl);
    }
  };
});

Essentially all I need is just a way to calculate the include URL (I need
this in several places, so just tacking a method on a controller doesn't
quite work), and more importantly, the templates that do finally get
included will be referencing things from further up the scope chain.

Is there a better way to do this than this approach?

Thanks!

  --m

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to