Dynamically Loading Controllers and ng-include

前端 未结 3 534
夕颜
夕颜 2021-01-31 16:57

At the moment I have an app that has a sidebar, and the sidebar loads different html templates using ng-include based on what operation the user chooses to do. It\'

3条回答
  •  無奈伤痛
    2021-01-31 17:30

    If i have understood you correctly what you can try would be to create a template view specifically to create a new leg.

    From the main controller implement some logic to show the template

    $scope.addLeg=function() {
       $scope.showAddLeg=true;
    }
    

    The AddLeg template view would load the controller and hence provide a mechanism to actually add new leg. The template would look like

    
    

    You can include this template inside you main html using ng-if + ng-include.

    Basically you can create multiple view and bind to same controller (but instance would differ). In this case the LegsController can be binded to multiple views to support the complete functionality.

提交回复
热议问题