2017-08-31 92 views
0

填充名稱列表,並在點擊該名稱時重定向到Google搜索。我需要幫助通過html將自定義填充數據name添加到網址中,該網址將使用Google搜索的自動搜索結果重定向訪問者。使用AngularDart中的其他自定義數據重定向到Url

app_component.html

 <h1>{{title}}</h1> 

    <h2>My favorite hero is: {{myHero.name}}</h2> 

    <p>Heroes:</p> 

    <ul> 

     <li *ngFor="let hero of heroes"> 

      <a href="https://www.google.co.in/search?q=">{{ hero.name }}</a> 

     </li> 

    </ul> 

app_component.dart爲您綁定您的數據,HTML

 import 'package:angular2/angular2.dart'; 
    import 'src/hero.dart'; 


    @Component(
     selector: 'my-app', 
     template: '''app_component.html''', 

     directives: const [CORE_DIRECTIVES],) 

     class AppComponent { 
      String title = 'Tour of Heroes'; 
      List<Hero> heroes = [ 
     new Hero(1, 'Windstorm'), 
       new Hero(13, 'Bombasto'), 
       new Hero(15, 'Magneta'), 
       new Hero(20, 'Tornado') 
     ]; 
      Hero get myHero => heroes.first; 
    } 

回答

1

同樣的方式,你可以將其綁定做HTML屬性,例如。這應該工作。

<a href="https://www.google.co.in/search?q={{ hero.name }}">{{ hero.name }}</a> 

順便說一句,你應該考慮到target="_blank"屬性添加到鏈接一樣,所以用戶會打開一個新的標籤搜索和您的應用程序仍將繼續。

+0

你能幫我嗎我該如何在資料按鈕上實現它 –

+0

根據按鈕的API文檔(https://material.angular.io/components/button/overview),它應該是類似於' click me!'。 – HoBi

+0

謝謝,但對不起,我想實現它在 Click me angular_components。 –

相關問題