2017-09-29 14 views
0

私はPolymerを初めて使い、iron-ajaxでajax呼び出しを作成しようとしています。私はエラーに遭遇し、そのgenerateRequest()は未定義です。iron-ajaxがgenerateRequest()を見つけることができません - メソッド

ポリマー1が使用中です。

私は鉄のajaxこのコマンドでインストール: bower install --save PolymerLabs/promise-polyfill#1

そして、あなたが見ることができるよう、私はいくつかの例と比較したがミスを見つけることができません<link rel="import" href="../bower_components/promise-polyfill/promise-polyfill-lite.html">

でそれをロードします。 誰かがアイデアや解決策を持っていますか?

これはコードです:

<!-- 
@license 
Copyright (c) 2016 The Polymer Project Authors. All rights reserved. 
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 
Code distributed by Google as part of the polymer project is also 
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 
--> 

<link rel="import" href="../bower_components/polymer/polymer.html"> 
<link rel="import" href="shared-styles.html"> 
<link rel="import" href="../bower_components/promise-polyfill/promise-polyfill-lite.html"> 
<dom-module id="my-view2"> 
    <template> 
    <style include="shared-styles"> 
     :host { 
     display: block; 

     padding: 10px; 
     } 
    </style> 

    <div class="card"> 
     <div class="circle">2</div> 
     <h1>View Two</h1> 
     <p>Demo output</p> 
    </div> 

    <template is="dom-repeat" items="[[repos]]"> 
     <span>{{items.name}}</span> 
    </template> 
    <button on-click="setajax">Click me</button> 

    <iron-ajax 
      id="ajax" 
      url="" 
      params='{"type":"all"}' 
      handle-as="json" 
      on-response="hresponse" 
      debounce-duration="300" > 
    </iron-ajax> 
    </template> 

    <script> 
    Polymer({ 
     is: 'my-view2', 
     setajax: function() { 
      this.$.ajax.url = "https://api.github.com/users/burczu/repos"; 
      this.$.ajax.params= {"type":"all"}; 
      this.$.ajax.generateRequest(); 
     }, 
     hresponse: function(request) { 
      console.log(request.detail.response); 
      console.log(this.$.ajax.lastResponse); 
     } 
    }); 
    </script> 
</dom-module> 

答えて

1

あなたはiron-ajaxをインストールする必要があります。

bower install --save PolymerElements/iron-ajax 

その後、あなたは次のコードを使用してインポートできます。

<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html"> 

あなたのコードは動作しますがあなたが上記のことをした後。

関連する問題