user944513
user944513

Reputation: 12729

why is two-way binding undefined in angularjs directive link function?

I am trying to send data from controller to directive , but i am getting undefined why ?

here is my code https://plnkr.co/edit/0gtFynDdvyY0sWqKGI2l?p=preview

I do the following steps

  <div img-upload="" previewData="data" method="POST" 
       url="webfreaks.in/dummyService">
  </div>

previewData="data" send data in directive in controller I defined like this

$scope.data =['sds']

but when i am trying to get its value in the directive . I am getting undefined undefined

why ?

link : function(scope,elem,attrs){
    var formData = new FormData();
    console.log(scope.previewData)

scope

scope : {
    url : "@",
    method : "@",
    previewData:'=',
},

Upvotes: 1

Views: 166

Answers (1)

Bill P
Bill P

Reputation: 3618

previewData in template has to be like this 'preview-data' (use kebab-case for bindings in the template):

<div img-upload="" preview-data="data" method="POST" url="webfreaks.in/dummyService"></div>

Upvotes: 2

Related Questions