0

Hi is it a good practice to have controller within a controller in angular?

For Example:

The body tag of my html has a controller called "CommonCtrl" within the html tag i'm loading a template using includes and inside the template i reuse the same controller.

Code:

Index.html

<body ng-controller="commonCtrl as vm">

 <header data-ng-include="'app/includes/header.html'"></header>

  <div ng-show="vm.showThisdiv">show this div</div>
</body>

header.html

<header id="header" ng-controller="commonCtrl as vm">
<span ng-show="vm.displayRegisterHeader" id="extr-page-header-space"> <span class="hidden-mobile">Already registered?</span> <a href="#/login" class="btn btn-danger">Sign In</a> </span>
    <span ng-show="vm.displayLoginHeader" id="extr-page-header-space"> <span class="hidden-mobile">Need an account?</span> <a href="#/register" class="btn btn-danger">Create account</a> </span>
</header>

1 Answer 1

1

You don't need to use ngController in header.html, Just remove the following line from header.html

<header id="header" ng-controller="commonCtrl as vm">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.