Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Problem

How to call function (GetLabelTextForEmployee) on angular component on employees.ts and employees.component.html ?

I work on asp.net core 2.1 web API with angular 6.

I make function on web API to get text of label from database and show on view

this function work on web API but in angular I cannot know how to call it inside angular ?

this is my function :

C#
[HttpGet("{tableName}/{FieldName}")]
        [Produces("text/plain")]
        public string GetReferenceFilesAsync([FromRoute] string tableName, [FromRoute] string FieldName)
        {
          var Result =  (from h in _context.ReferenceFiles
                          where h.TableName == tableName && h.FieldName == FieldName
                          select h.FieldName).FirstOrDefault();
            if(Result==null)
            {
                Result = "Not Exist";
            }
           
            return (Result);
           

        }

Function above return only one string value for label

What I have tried:

on Angular Api service i do as below
GetLabelTextForEmployee(tableName:string,FieldName : string)
              {
                return this.http.get('https://localhost:44326/api/reference/' + tableName + '/' + FieldName);
              }

on main page or component Employee
getreferencefile(tableName:string,FieldName : string) :void
{
  this.api.GetLabelTextForEmployee(tableName,FieldName).subscribe( data=>{
    this.returnedData = data; //SUBSCRIBE HERE
    console.log(data);
  }); 
}

//on view how to call on get reference file function
Posted
Updated 23-Feb-19 16:16pm

1 solution

I would suggest to modify the service a little bit to tell the method to expect a text instead of JSON object.

JavaScript
public GetLabelTextForEmployee(tableName:string,FieldName:string): Observable<any> {
        return this.http
            .get('https://localhost:44326/api/reference/' + tableName + '/' + FieldName, {
                responseType: 'text',
            });
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900