Lai32290 Lai32290 - 1 year ago 91
AngularJS Question

How to define Angular directive must be a child of a specific directive in Angular?

I'm creating directive to

, how to can I configure it must be child of directiveA?

Like this example:


must be child of
, if not, occur some exception

Answer Source

You can use the require parameter to effort the require of a parent directive like the code below.

app.directive('mHeader', function() {
  return {
    require: '^^myModal',
    restrict: 'E',
    transclude: true,
    link: function(scope, element, attrs, myModalCtrl) {
    templateUrl: 'my-header.html'

Also, when using require, you can have access to the parent controllers, as you can see on myModalCtrl.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download