【发布时间】:2016-10-13 17:22:28
【问题描述】:
如何连接'index.aspx.cs - public string getContactID() { return 1; }' 到 app.component.ts
这个事件需要任何方法都可以。
整个项目都在 Visual Studio 2015 Web Api 中
app\app.component.ts
SomethingClick() {
ID:number = 'index.aspx.cs'.getContactID();
}
索引.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="CA_CopyLine.index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<base href="/"/>
<title>Angular 2 QuickStart</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="styles.css"/>
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="https://unpkg.com/core-js/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.6.21?main=browser"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3"></script>
<script src="https://unpkg.com/systemjs@0.19.27/dist/system.src.js">
</script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app></my-app>
</body>
</html>
索引.aspx.cs
public partial class index {
[WebMethod]
public string getContactID()
{
return 1;
}
}
app\app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app/app.component.html',
styleUrls: ['./app/app.component.css']
})
export class AppComponent { }
SomethingClick() {
ID:number = 'index.aspx.cs'.getContactID();
}
【问题讨论】:
-
如果您使用 Web API,您可能希望实际使用 Web API(通过
ApiController)而不是WebMethodWeb 服务。 -
问题是,这个项目是一个 Web API,aspx 用于使用 DLL 文件
标签: c# asp.net angularjs angular