I dont understand how controllers is connecting with views in Hawtio project.

for example, view:

<div ng-controller="Core.AboutController">
  <div class="welcome">
    <div class="about-display" compile="html"></div>
  </div>
</div>

controller declaration:

module Core {
  export function AboutController($scope, $location, jolokia, branding, localStorage) {
    //...
  }
  //...
}

I expected to find something like that:

angular.module('moduleName').controller('Core.AboutController', Core.AboutController);

But found none. How it works?

有帮助吗?

解决方案

This works because in the absence of any registration with angular i.e. angular.module('moduleName').controller('Core.AboutController' angular looks at window and tries to resolve it. Which is what

module Core {
  export function AboutController

does. After this line window.Core.AboutController will point to the correct function and that is what angular just found.

其他提示

just look at the attribute in the first line of the HTML sample you posted.

ng-controller="Core.AboutController"

There are (As far as I know) two ways of associating a view to a controller. The first is with a an attribute, like in this example. The second is while configuring the router:

angular.module('MyApp', ['Core.Aboutcontrollers']).
config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/path', {templateUrl: 'partials/myfile.html'   });
}]);

Don't do both of them, or your controller will be invoked twice.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top