TemplateUrl Directive: AngularJs

can I view the scope in the templateUrl directive?

I want to do something like this:

mDirective.directive('directive', [function () {
    return {
        restrict: 'A',
        scope: {
            types :'=types'
        },

templateUrl:'.mytemplate/'+scope.types+'.html'
+4
source share
1 answer

The scope is not available in the templateUrl directive. To do this, there is a function request on github: Either add an attribute region that is passed to the templateUrl function or preprocessor attributes based on the region parameters .

Here are two options (the second is more general):

Attribute: Area not available. But the original attributes. So, if the source attribute works for you, for example, if it's just a static string like this:

<div directive types="test1"></div>

templateUrl. , URL- , :

templateUrl: function(elem, attrs){ return ('mytemplate/'+attrs.types+'.html')},

, types , :

ngInclude ngInclude. templateUrl template, ngInclude / :

template: '<div ng-include src="\'mytemplate/\'+types+\'.html\'"></div>',

. ngInclude .

, , ngInclude.

+7

Source: https://habr.com/ru/post/1523556/


All Articles