使用AngularDart中的其他自定义数据重定向到Url
问题描述:
填充名称列表,并在点击该名称时重定向到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;
}
答
同样的方式,你可以将其绑定做HTML属性,例如。这应该工作。
<a href="https://www.google.co.in/search?q={{ hero.name }}">{{ hero.name }}</a>
顺便说一句,你应该考虑到target="_blank"
属性添加到链接一样,所以用户会打开一个新的标签搜索和您的应用程序仍将继续。
你能帮我吗我该如何在资料按钮上实现它 –
根据按钮的API文档(https://material.angular.io/components/button/overview),它应该是类似于' click me!'。 – HoBi
谢谢,但对不起,我想实现它在 Click me material-button> angular_components。 –