Just started learning Angular and I'm working on creating a top-nav directive:
<html>
<body ng-app="myApp">
<top-nav></top-nav>
</body>
</html>
Everything is running smoothly. However, I have a button outside of the top-nav that needs to trigger the showLoginDialog() method within the topNav's controller.
To make this functionality work, I had to separate the controller from the top-nav like this:
<html>
<body ng-app="myApp">
<div ng-controller="TopNavController as topNav">
<top-nav></top-nav>
</div>
<!-- More markup here.... -->
<button ng-click="topNav.showLoginDialog()">
</body>
</html>
My concern is: Is it considered bad practice to remove the controller from the directive in order for external elements to access it?
Edit: Just an additional note - the "login popup" only appears when clicking the "Login" button in the top-nav. But I also want it to pop up if someone clicks the "Register" button on the homepage. Hence, the question about calling it from outside.