D
D
Denis2014-07-03 08:36:12
Angular
Denis, 2014-07-03 08:36:12

Angularjs One controller for different areas of the page. How to transfer data?

There is such layout

<div ng-app>
    <div ng-controller="MyCtrl">
        <input ng-model="torro" /><div>{{num}}- {{torro}}</div>
    </div>
    
    <div ng-controller="MyCtrl">
        <div>Ещё раз: {{num}} - {{torro}}</div>
    </div>
    
</div>

And a simple controller
function MyCtrl($scope) {
    $scope.num = 1560;
}

The question is how to make {{torro}} visible in the second div as well, where Ещё раз: {{num}} - {{torro}}
Example on jsfiddle jsfiddle.net/buHc8
ANSWER (solution in my case):
<div ng-app>
    <div ng-controller="MyCtrl">
        <input ng-model="$parent.torro" />
        <div>{{num}}- {{torro}}</div>
    </div>
    
    <div ng-controller="MyCtrl">
        <div>дубль {{num}} - {{torro}}</div>
    </div>
    
</div>

Thanks SergeiMeketyuk

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Meketyuk, 2014-07-03
@cjbars

Answer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question