在Polymer.js中, Google客户端加载程序用于加载特定的客户端。它与带有JavaScript客户端库的Google API一起使用。
运行以下命令以在你的项目目录中安装polymer_google-client-loaderelement。之后, 你可以在应用程序中使用此元素:
bower install --save GoogleWebComponents/google-apis
它将在bower_components文件夹下安装polymer_google-client-loader的所有相关元素。
例:
创建一个index.html文件并在其中添加以下代码, 以查看Polymer.js中google-client-loader元素的用法。
<html>
<head>
<script src = "bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel = "import" href = "bower_components/google-apis/google-apis.html">
</head>
<body>
<div id = "loadedmsg"></div>
<template id = "googleclient" is = "dom-bind">
<google-client-loader id = "shortener"
name = "urlshortener"
version = "v1"
on-google-api-load = "loadedShortener">
</google-client-loader>
<google-js-api
on-js-api-load = "msgloaded">
</google-js-api>
<google-plusone-api
on-api-load = "msgloaded">
</google-plusone-api>
</template>
<script>
var googleclient = document.querySelector('#googleclient');
googleclient.loadedShortener = function(event) {
var request = event.target.api.url.get ({
shortUrl: 'http://goo.gl/fbsS'
})
request.execute(function(resp) {
});
};
googleclient.msgloaded = function(e) {
document.querySelector('#loadedmsg').innerHTML +=
e.target.localName + ' is loaded' + '<br>';
};
</script>
</body>
</html>
评论前必须登录!
注册