1

I am using angular 1.5 and UI route.

Due to structure limitation we are loading under single state both filters view and content view(mostly for dataset presentation).

I'm trying to achieve single-scope for multiple views, it means: I want my filter view to be able trigger functions from loaded controller on content view.

My state deceleration looks like this:

.state('somestate', {
    url: '/somestate',
    views : {
        "content" : {
            templateUrl: 'dataset.html',
            controller: "someController"
        },
        "filters" : {
            templateUrl: 'filters.html',
        }

    }

})

I want to be able to trigger functions from filters.html, something like this

<div ng-click="doSomething()"></div>

Considering doSomething() deceleration made inside someController

Michael Kisilenko
  • 491
  • 2
  • 6
  • 15

2 Answers2

1

I'm not sure to understand your problem ... If you want to use the same controller, just do it ...

This way :

.state('somestate', {
    url: '/somestate',
    views : {
        "content" : {
            templateUrl: 'dataset.html',
            controller: "someController"
        },
        "filters" : {
            templateUrl: 'filters.html',
            controller: "someController"
        }

    }

})

or using ng-controller in your template file.

Steeve Pitis
  • 4,283
  • 1
  • 21
  • 24
0

Use "controller as" syntax.

If the controller is declared in the state:

controller: 'SomeController`,
controllerAs: 'some'

If inside an html tag:
ng-controller="SomeController as some"

Then inside your templates you can access the controller's scope as some.someFunc()

George Kagan
  • 5,913
  • 8
  • 46
  • 50
  • I have already tried it. I'm not sure why it didn't work, maybe it does not because filter's view is inside other directive, so if we lookup scopes encapsulation we will find that filters is somewhere a child -> child -> child of the content view. – Michael Kisilenko Oct 05 '16 at 12:01
  • So what exactly are you trying to achieve? It's unclear – George Kagan Oct 05 '16 at 12:01
  • 1 controller initialized by view1 and view2 is only a template loaded which triggers methods from shared controller. single controller's scope shared on multiple views – Michael Kisilenko Oct 05 '16 at 12:05