Skip to main content
update
Source Link
atefth
  • 1.6k
  • 13
  • 27

You can pass the model to the directive like this -

<div header showprofile="false" search="search">
    <div class="searchView col-xs-12">
        <input type="text" placeholder="Search" ng-model="search" />         
    </div>
</div>

Update your directive to accept it

.directive('header', function() {
  function link(scope, element, attrs) {
    scope.$watch(attrs.search, function(value) {
      console.log(value);
    });
  }
  return {
    restrict: 'EA',
    scope: {
      showprofile: '=',
      search: '=',
    },
    link: link
  };
});

UPDATE Here is a fiddle.

Hope that helps.

You can pass the model to the directive like this -

<div header showprofile="false" search="search">
    <div class="searchView col-xs-12">
        <input type="text" placeholder="Search" ng-model="search" />         
    </div>
</div>

Update your directive to accept it

.directive('header', function() {
  return {
    restrict: 'EA',
    scope: {
      showprofile: '=',
      search: '='
    }
  };
});

Hope that helps.

You can pass the model to the directive like this -

<div header showprofile="false" search="search">
    <div class="searchView col-xs-12">
        <input type="text" placeholder="Search" ng-model="search" />         
    </div>
</div>

Update your directive to accept it

.directive('header', function() {
  function link(scope, element, attrs) {
    scope.$watch(attrs.search, function(value) {
      console.log(value);
    });
  }
  return {
    restrict: 'EA',
    scope: {
      showprofile: '=',
      search: '=',
    },
    link: link
  };
});

UPDATE Here is a fiddle.

Hope that helps.

Source Link
atefth
  • 1.6k
  • 13
  • 27

You can pass the model to the directive like this -

<div header showprofile="false" search="search">
    <div class="searchView col-xs-12">
        <input type="text" placeholder="Search" ng-model="search" />         
    </div>
</div>

Update your directive to accept it

.directive('header', function() {
  return {
    restrict: 'EA',
    scope: {
      showprofile: '=',
      search: '='
    }
  };
});

Hope that helps.