在指令AngularJS 1.5中需要父组件

时间:2016-07-21 09:19:08

标签: angularjs angularjs-directive angularjs-components

如何在指令中要求组件?您可以在另一个指令中要求指令的控制器,并且您可以在另一个组件中需要一个组件。但是如何在指令中要求组件控制器?

指令:

export class Directive {

        require = "^^parentComponent";  
        restrict = "A";
        link = (scope, element, attrs, parentComponent) => {

    }

    app.directive("someDirective", /* Init code omitted for brewity */);
}

Html:

<parent-component>
     <div some-directive> </div>
</parent-component>

我收到以下错误:

Error: [$compile:ctreq] Controller 'parentComponent', required by directive 'someDirective', can't be found!
http://errors.angularjs.org/1.5.0/$compile/ctreq?p0=InvoiceCre

1 个答案:

答案 0 :(得分:-1)

require: '^parentComponent' 

作品

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