alfredopacino
alfredopacino

Reputation: 3241

Controller outside ui-view

I want to use a unique controller inside and outside ui-view. Using ng-inspector I see <div ui-view> has another instance of myController, not sure why.

<div class="container" ng-controller="myController">
    ::{{_path}}
    <a ng-click="action()">action</a>
    <div ui-view class="view"></div>
</div>

app.controller("myController",function ($scope) {
        $scope.action = function(){
          $scope._path= "changed";
         }
});

The result of this issue is if I click on <button ng-click="action()">action</button> I see the changes in _path, if the same button is inside ui-view, _path doesn't changes. How can I make this work?

Upvotes: 0

Views: 198

Answers (1)

Aibu
Aibu

Reputation: 401

When you define your state you can specify the controller you want to use inside your view as follows:

$stateProvider.state('myState', {
    url: '/my-state',
    templateUrl: '/templates/my-state.html',
    controller: 'myController'
});

Hope this helps.

Upvotes: 2

Related Questions