简体   繁体   English

在AngularJS中动态切换ng-include和ng-controller

[英]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. 我想基于所选的当前选项卡动态切换ng-include和ng-controller。

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. 可能这里最大的问题是Angular期望控制器指向实际控制器而不是指向具有控制器名称的字符串。

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. 您可以使用Routing方法。

I Hope this will help you. 我希望这能帮到您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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