2

I have a controller defined inside a module:

angular.module('myModule').controller('MyCtrl', function ($scope) {
$scope.property = 'myproperty'; });

A partial is included in the main html like this:

<div ng-include src="'partial/mypartial.html'"></div>

Is it possible to reference MyCtrl inside mypartial.html? e.g. somehow like this:

<div ng-controller="myModule.MyCtrl">

Thanks!

doorman
  • 15,707
  • 22
  • 80
  • 145
  • 4
    if 'myModule' is your top level module (ng-app) then you can just reference the controller as "MyCtrl". I think it should work like that even if you are using a submodule (as long as you passed it as a dependency to your main module) – holographic-principle Mar 21 '13 at 22:04
  • Thanks, that was the problem. I had to pass my submodule as a dependecy to the main module – doorman Mar 22 '13 at 20:14

1 Answers1

1

Given the angular javascript:

angular.module('myModule').controller('MyCtrl', function ($scope) {
  $scope.property = 'myproperty'; });

Your view setup should look something like:

<html ng-app>
  <head>
  </head>
  <body>
    <div ng-controller="MyCtrl">
      {{property}}
    </div>
  </body>
</html>

The above code should generate:

myproperty
Brian Petro
  • 1,577
  • 16
  • 32