使用angular2用asp.net 5的Razor视图 [英] Using angular2 with asp.net 5 Razor view

查看:92
本文介绍了使用angular2用asp.net 5的Razor视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在角1我们设置 NG-控制器在的Razor视图的任何HTML标记和使用的角度控制器定义的函数。我怎样才能达到这个观点Angular2?
例如,我要点击在剃刀查看一个HTML标记并从angular2组件或指令调用的方法。

In Angular 1 we set ng-controller for any HTML tag in the Razor view and use the functions defined in the angular controller. How I can achieve this view Angular2? For example I want to click on a HTML tag in Razor View and call a method from an angular2 component or directive.

任何帮助将AP preciated。

Any help will be appreciated.

推荐答案

有是控制器的角度没有更多的概念。现在的观点是由组件管理。

There is no more concept of controller in Angular. Views are now managed by components.

在与组件关联的模板,你可以利用它的方法和它的状态。下面是低于一个例子:

Within template associated with a component, you can leverage its methods and its state. Here is a sample below:

import {Component} from 'angular2/core';
import {CompanyService, Company} from './app.service';

@Component({
    selector: 'company-list',
    template: `
      <h1>Companies</h1>
      <ul>
        <li *ngFor="#company of companies">
          <a href="#" (click)="selectCompany(company)">
            {{company.name}}
          </a>
        </li>
      </ul>
    `
})
export class ListComponent {
  constructor(service:CompanyService,router:Router) {
    this.service = service;
    this.companies = service.getCompanies();
  }

  selectCompany(company:Company) {
    (...)
    return false;
  }
}

点击事件连接,使用语法 selectCompany 方法(点击)

The click event is attached to the selectCompany method using the syntax (click).

希望它可以帮助你,
蒂埃里

Hope it helps you, Thierry

这篇关于使用angular2用asp.net 5的Razor视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆