javascript - Passing attrs as $scope variables in Angular -


i have directive , i'm trying attrs , pass them $scope, i'm not quite sure how that. more i'm trying set attributes in template equal name set in date-picker tag. tried setting them variable, didn't work. , further clarification appreciated. thanks!

html

<date-picker id="dateendpicker" name="date_end"></date-picker> 

js

app.directive('datepicker', function(){   return {   scope: {           name : '@'          },   restrict: 'ae',   replace: 'true',   template: '<div class="date"><div class="input-group"><input type="text" class="form-control" id="{{this_name}}" name="{{this_name}}" ng-model="event.{{this_name}}" required/><span class="input-group-addon"><i class="fa fa-calendar"></i></span></div></div>',   controller: ['$scope', function($scope){         $scope.this_name = this_name;   }],   link: function(scope, element, attrs){     var this_name = attrs.name;   }   } }); 

because of how you've defined directive scope:

  scope: {       name : '@'   } 

name variable on scope. if you're not doing special on controller\link functions, can drop them entirely, , in template reference {{name}}. note if you're creating scope bindings '@', in html should pass data angular expression, meaning:

name="{{date_end}}" 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -