Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wiring together polymer components and angular controllers

I've just started to experiment with polymer and try to use it together with AngularJS in one single-page app. Therefore I picked up two polymer-ui-components: polymer-ui-sidebar-menu and polymer-ui-pages. Every time the user selects an item from the sidebar, the pages component should show its item with same index...

But how to wire these two components?

I've tried to use the onclick event from the menu, but this don't work as expected.

Maybe there exists any useful documents about polymer in the world wide web besides their own documentation?

UPDATE:

HTML:

<polymer-ui-sidebar-menu label=Channels>
  <polymer-ui-menu-item ng-repeat="channel in channels"
    ng-click=select($index)
    label="{{ channel }}"
    icon=menu>
  </polymer-ui-menu-item>
</polymer-ui-sidebar-menu>
<polymer-ui-pages>
  <span ng-repeat="channel in channels">content: {{ channel }}</span>
</polymer-ui-pages>

Controller:

$scope.select = function (index) {
  angular.element("polymer-ui-sidebar-menu")[0].selected = idx;
  angular.element("polymer-ui-pages")[0].selected = idx;
};

To get the selector in angular.element(selector) working, you have to include jquery before angular and polymer before jquery!

like image 875
net.user Avatar asked Oct 21 '22 21:10

net.user


1 Answers

I made a video demonstrating how a web component (Polymer element) can talk to an Angular directive: http://www.youtube.com/watch?v=p1NpZ-0Op0w&list=PLRAVCSU_HVYu-zlRaqArF8Ytwz1jlMOIM&index=1

The example in that video data-binds the components' attributes using Angular's data binding feature, but you should be able to use other features to get things working. Have you tried adding ng-click on <polymer-ui-sidebar-menu>?

like image 53
ebidel Avatar answered Oct 23 '22 22:10

ebidel