Is it possible to set ng-view to replace: true?

I am integrating Angular into a web application, and I noticed that the shell is messing with some CSS on the page. After examining the directives, I saw that custom directives can have a “replace” property to set true so that templateUrl is directly replaced instead of being wrapped in directive tags.

Is there a way to do the same with ng-view or, as a rule, with any Angular directive? Thanks for the help!

+4
source share
2 answers

I think your best bet is to decorate the original directive ng-viewand add a switch to it replace:true. Note that the replacement will be - hah - replaced in the next major version of angularjs, but for now it will work:

app.config(function($provide) {
    $provide.decorator('ngViewDirective', function($delegate) {
        var directive = $delegate[0];
        directive.replace = true;

        return $delegate;
    });
});

And of course jsFiddle: Here

+2
source

Is there a way to do the same with ng-view

I can't think of a way to do this without editing the Angular source or something else. replaceDesigned for custom directives, not (required) inline ones.

or, as a rule, any Angular directive? Thanks for the help!

. - , , . , template'd ( , ), , , , .

, , Angular , " " , , , .

ngInclude/ngView -esque, .

, , (, , ) :

app.directive('myRender', function ($compile, $http) {
  return {
    restrict: 'E',
    link: function (scope, element, attrs) {
      var newScope;
      var newElement;

      attrs.$observe('url', function (value) {
        if (value) {
          $http.get(value).then(function (result) {
            if (newElement !== undefined) {
              newElement.remove(); 
            }
            newElement = angular.element(result.data);

            if (newScope !== undefined) {
              newScope.$destroy();
            }
            newScope = scope.$new();

            $compile(newElement)(newScope);
            element.parent().append(newElement);
          });
        }
      })
    }
  }
});

http://plnkr.co/edit/Vm96f2rQsT2PX1C3rgK8?p=preview

- css Angular, angular.

angular, .

+1

All Articles