简体   繁体   中英

Dynamically switch ng-include and ng-controller in AngularJS

I have a section on my page with a few tabs which have to include a partial and controller. I would like to dynamically switch a ng-include and ng-controller based on the current tab selected.

Probably the biggest issue here is that Angular expects a controller to point to the actually controller and not to a string with the controller name.

I tried a few different things, but I can not get it to work.

$scope.tab.active = {
    view: 'activetabview.html',
    controller: 'ActiveTabController'
}

<section ng-include src="tab.active.view" ng-controller="tab.active.controller">
</section>

You can use Routing method.

I Hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM