Angular4 & MVC方法调用

前端之家收集整理的这篇文章主要介绍了Angular4 & MVC方法调用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

参考

1,定义方法

public class HomeController : DSController
    {
        [HttpGet]
        public JsonResult GetUserAccount(string valu)
        {
            return new JsonResult()
            {
                Data= GetUserSystemRecordDTO(valu)
            };
        }
    }

2,方法调用

import { Injectable } from '@angular/core';
import { Http,Response,Headers,URLSearchParams,RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { HttpParams } from '@angular/common/http';

GetUserAccount(name:string): Observable<Article[]> {
        const url = "http://localhost:22294/home";
        const headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'});
        const paras = new URLSearchParams();
        paras.append('valu','xxx' );     
        const options = new RequestOptions({ headers: headers,params:paras });
        return this.http.get(this.articleUrl+"/GetUserAccount",options).subscribe(
            data => {
                alert('ok');
              },error => {
                console.log(JSON.stringify(error.json()));
              });
    }
原文链接:https://www.f2er.com/angularjs/145865.html

猜你在找的Angularjs相关文章