You can use an 'Element' or an 'Attribute' in a Directive.
All you need to do is to state what you want to use in your
template in your 'Directive' file i.e.
restrict: 'A' ... For Attributes and
restrict: 'E' ... For Elements and
restrict: 'AE' ... For Elements and Attributes.
Refer to following example.
//------------------------------------------------------------------------------------
# change-password.directive.js
# In this case you are using ... restrict: 'A' for Attributes
# So your template will have the following
# <!-- Directive As Attribute -->
# <div foo-change-password></div>
# Note that 'fooChangePassword' in the Directive below
# changes to 'foo-change-password'in your template
(function() {
'use strict';
angular
.module('app.foo.authentication')
.directive('fooChangePassword', changePassword);
/* @ngInject */
function changePassword() {
var directive = {
restrict: 'A',
templateUrl: 'app/foo/authentication/change-password/change-password-validation.tmpl.html',
transclude: true,
replace: true,
bindToController: true,
controller: 'ChangePasswordController',
controllerAs: 'vm',
link: link
};
return directive;
function link($scope, $element, attrs) {
}
}
})();
//------------------------------------------------------------------------------------
# change-password.directive.js
# In this case you are using ... restrict: 'E' ... For Elements
# So your template will have the following
# <!-- Directive As Element -->
# <foo-change-password></foo-change-password>
# Note that 'fooChangePassword' in the Directive below
# changes to 'foo-change-password' in your template
(function() {
'use strict';
angular
.module('app.foo.authentication')
.directive('fooChangePassword', changePassword);
/* @ngInject */
function changePassword() {
var directive = {
restrict: 'E',
templateUrl: 'app/foo/authentication/change-password/change-password-validation.tmpl.html',
transclude: true,
replace: true,
bindToController: true,
controller: 'ChangePasswordController',
controllerAs: 'vm',
link: link
};
return directive;
function link($scope, $element, attrs) {
}
}
})();
//------------------------------------------------------------------------------------
# change-password-validation.tmpl.html
# This will be the template that you will inject in the 'change-password.tmpl.html'
# below. Note that the template being injected must have a <div> ... </div>.
# Otherwise your page wont render.
<div>
<form name="changePasswordForm">
<md-input-container class="md-block">
<label for="password" translate>CHANGE-PASSWORD.PASSWORD.LABEL</label>
<input id="password"
label="password"
name="password"
type="password"
ng-model="vm.user.password"
tri-same-password="changePasswordForm.confirm"
required/>
</md-input-container>
<md-input-container class="md-block">
<label for="password" translate>CHANGE-PASSWORD.PASSWORD_CONFIRM.LABEL</label>
<input id="confirm"
label="confirm"
name="confirm"
type="password"
ng-model="vm.user.confirm"
ng-keypress="handleKeyPress($event)"
tri-same-password="changePasswordForm.password"
ng-minlength="8"
required/>
</md-input-container>
<div layout="row" layout-align="center center">
<md-progress-circular ng-show="vm.loading" md-mode="indeterminate"></md-progress-circular>
</div>
<div layout="row" class="change-password-buttons-margin-top">
<md-button
class="md-warn full-width md-raised md-button"
ng-click="vm.backToLoginClick()"
translate="CHANGE-PASSWORD.LOGIN"
aria-label="{{'CHANGE-PASSWORD.LOGIN' | translate}}">
</md-button>
<md-button
class="md-primary full-width md-raised md-button"
ng-disabled="vm.user.password !== vm.user.confirm"
ng-click="vm.changePasswordClick()"
translate="CHANGE-PASSWORD.BUTTON"
aria-label="{{'CHANGE-PASSWORD.BUTTON' | translate}}">
</md-button>
</div>
</form>
</div>
//------------------------------------------------------------------------------------
# change-password.tmpl.html
# In this case
# <!-- Directive As Element -->
# <foo-change-password></foo-change-password>
<div layout="row" flex layout-padding layout-fill layout-align="center center">
<div class="change-password-card" flex="40" flex-lg="50" flex-md="70" flex-xs="100">
<md-card>
<md-toolbar class="padding-20 change-password-card-header">
<div layout="row" layout-align="center center">
<h1 class="md-headline" translate>CHANGE-PASSWORD.TITLE</h1>
</div>
</md-toolbar>
<md-content class="md-padding">
<!-- Directive As Element -->
<foo-change-password></foo-change-password>
</md-card>
</div>
</div>
//------------------------------------------------------------------------------------
# change-password.tmpl.html
# In this case
# <!-- Directive As Attribute -->
# <div foo-change-password></div>
<div layout="row" flex layout-padding layout-fill layout-align="center center">
<div class="change-password-card" flex="40" flex-lg="50" flex-md="70" flex-xs="100">
<md-card>
<md-toolbar class="padding-20 change-password-card-header">
<div layout="row" layout-align="center center">
<h1 class="md-headline" translate>CHANGE-PASSWORD.TITLE</h1>
</div>
</md-toolbar>
<md-content class="md-padding">
<!-- Directive As Attribute -->
<div foo-change-password></div>
</md-content>
</md-card>
</div>
</div>
//------------------------------------------------------------------------------------
# In both instances your page will render.