[AngularJS] Angular 1.5 $transclude with name slot

Source: Internet
Author: User

In Angular 1.5, there is no link and component. So with If you transclude, you cannot access the fifth arguement in link function, which is transcludefn.

But in v1.5, you can access $transclude in controller.

And what are the can do for so is check whether the transclude element was passed in or not. For the also need to use named slots, not default transclude:true.

See Example:

classServicelistcontroller {Constructor ($transclude) { This. $transclude =$transclude; } hastransclude () {return  This. $transclude. isslotfilled ('Actions'); }}ConstClmservicelistcomponent ={bindings: {...}, transclude: {'Actions':'? clmactions'}, Controller:servicelistcontroller, Controlleras:'VMS', Template:require ('./service-list.html')};exportdefault(ngmodule) ={ngmodule.component ('clmservicelist', clmservicelistcomponent);} 

In the example, we have a directive call ' clmactions ', and gave slot name as ' actions '.

So-can use:

this. $transclude. isslotfilled ('actions');

To check whether the transclude element was defined or not.

In HTML:

< clm-service-list >      < clm-actions >           <  ></clm-action>       </clm-actions > </ clm-service-list >

If we gave the clm-actions tag, the Hastransclude () function in controller would return ' true ' if you remove clm-actions t AG, the function would return false.

[AngularJS] Angular 1.5 $transclude with name slot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.