AngularJS : How to pass data from directive to controllers function

冷暖自知 提交于 2019-12-03 00:45:31

In order to pass in your data from your directive, you will need to do it like this:

<youtube-list search="search" dial="addTrackFromPicker(data)"></youtube-list>

Then, in your template:

<div class="media list-group-item" ng-repeat="item in entries">
    <a type="button" ng-click="dial({data: item.id.$t})">
        <img  ng-src="{{item.media$group.media$thumbnail[0].url}}">
    </a>
</div>

You can use an "argument name" other than data if something else makes more sense for your situation. See Angular's documentation on scope for detailed info on how this works.

Isolated Scope: pass some values from the parent scope to the directives

There’re 3 types of prefixes AngularJS provides

  1. "@" ( Text binding / one-way binding )
  2. "=" ( Direct model binding / two-way binding )
  3. "&" ( Behaviour binding / Method binding )

All these prefixes receives data from the attributes of the directive element.

 class="directive"

 name="{{name}}"

 color="color"

When the directive encounters a prefix in the scope property, it will look for an attribute ( with same property name ) on directive’s html element

 scope : {    
  name: "@"    
 }

I've followed this linkhttp://jsfiddle.net/shidhincr/pJLT8/10/light/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!