Custom Components Listen to events from other components

时间:2016-04-15 14:54:36

标签: javascript events polymer polymer-1.0

Is it possible to share events between custom polymer components.

I want to append a header to every request i send. For this purpose I wanted to create a custom element.

<template>

</template>
<style is="em-header-inject">
</style>
<script>
    (function() {
        'use strict';

        Polymer({
            is: 'em-header-inject',

            properties: {
                listeners: {
                    'em-send-request': 'handleRequest'
                }
            },
            computeHeaders: function() {
                return {'Authorization' : 'Bearer {' +  app.accessToken + '}'};
            },
            handleRequest: function(request) {
                console.log("handling request", request);
                request.header = this.computeHeaders();
            }


        });
    })();
</script>

in any other component I want to do something like this

this.fire('em-send-request', addRiderRequest);

But the event listener does not see the event being fired. Is this by design or am I missing something?

0 个答案:

没有答案