Problems
Using angularJS ui router with 3 ui views, Leftbar for showing menu, topbar for showing application title and actions and content view for displaying actual content.
Clicking links in leftbar trigger change in state which in turn change the view of the content correspondingly. At the same time, current usage of the tab will be highlighted.
Problem is the color highlight is wrong. Surfing content B highlights menu of title A.
Reasons and Solutions
The mixture of usage of "ng-click" and "ui-serf" in menu bar item causes the issue, I somehow used both ng-click to change router state and the view simultaneously, but the funny thing is when you change the router state, the binding will re-do and all the view binding will reset to initial state. This explains why when I click the link one more time, the color highlight becomes correct.
To fix this, I change the implementation method, I bind the $stateParams and $state to $rootScope as follows
After assigning, I can access the current state directly in the view template and therefore save the effort on changing the state in ng-click References
jquery, bootstrap etc. is the self-defined name of js scripts to load, they are loaded in order
We must load the controller module for the AngularJS controller to work properly
Inside require function we have a second require function,which is called sugar function, it only loads the required modules for use inside the function, if you don't need it, you are NOT required to include in function parameters.
angular.bootstrap is to manually trigger the start of angularJS, which is highly recommended to use when cooperate with requireJS
When this was set, NO exists in the html view or AngularJS will throw errors
Normally, we will ignore the first parameter of the define function and let requireJS to use the file name as the module name (recommended)
Second array parameter tells requireJS that insiderApp module requires angular, angular-route and angular-animate to be loaded before executing the insiderApp module
function parameter "angular" is returned by the angular function, this object is for the implementation of insiderApp
Return the insiderApp variable or not depends on whether or not other modules need insiderApp, normally you need to return it.
var insiderApp = angular.module("insiderApp",["ngRoute", "ngAnimate"]); Just like usual, start the angular module, we can do any configuration of the angular object in this file.
controller.js
Just like usual, controller of the Angular object
define(['insiderApp'],function(insiderApp)...
Controller rely on insiderApp for adding controller to the Angular module, so we need to put insiderApp to the array and use it inside the function