V
V
Vitaly2015-08-26 11:49:51
Angular
Vitaly, 2015-08-26 11:49:51

How to change the value of a variable in a directive when it changes in a controller?

For example, I have this directive:

.directive('myDir',function(){
      return {
        restrict : 'E',
        scope: {
          first : '=',
          second: '='
        },
        template : '{{first}}',
        link : function(scope,el,attr){
                 scope.second = 'from directory and '+ scope.first;
        }
      }

    })

HTML :
<my-dir data-first="FromCtrl" data-second="directoryresult"></my-dir>
      <br>
      {{directoryresult}}

<button ng-click="ChangeFromCtrl()">срфтпу</button>

And controller :
.controller('MyCtrl', function($scope) {
  $scope.FromCtrl = 'love';
  $scope.ChangeFromCtrl = function(){
    $scope.tst = 'pice';
  }

When a button is clicked, FromCtrl only changes its value in the template (from a directive), how do I change the values ​​of the second variable inside the directive and directoryresult in a non-directive, when changed by a controller call?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-08-26
@couchemar

apparently you want to achieve something similar to plnkr.co/X3NkVbAHbLd1LlTYVyCN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question