0

I am using angularjs ui tour https://github.com/benmarch/angular-ui-tour I have successfully installed the directive, I now want to initialize the directive in my controller when the page is loaded.

On my routes, I have the following code

when('/start', {
    templateUrl: 'start.html',
    controller: 'startController'      
})

On the template start.html, I have the following code

<div ui-tour class="myClass">

So I want to access the tour var of ui-tour scope from startController, how can I do that?

Petran
  • 7,677
  • 22
  • 65
  • 104

2 Answers2

0

That depends on how directive is defined. Does it create a new scope or not? Is it's scope proto inherited or isolated one. The simplest solution is to make your directive not create a new scope but use parent's one. If it is the same scope, simply call a function in the directive from parents controller like you would do for a function in that controller.

For more info about why is not a straightforward answer and what are the options when defining directives concerning scope, I find this well explained on the following link:

directives and scopes

DanteTheSmith
  • 2,937
  • 1
  • 16
  • 31
0

Taking a look at the documentation, it looks like it's possible. Via the uiTourService documentation

yourModule.controller('startController',
['$scope', 'uiTourService', function($scope, uiTourService) {
    var myTour = uiTourService.getTour();
}]);
Gabe Gates
  • 902
  • 1
  • 14
  • 19