2017-05-05 55 views
1

我试图将两个url合并成一个url。将angular2中的两个URL合并成一个 - ionic2

let url = "http://example.com/public/"; 

而且我有来自API的路径"/samples/leads/Import_Leads_Sample.csv"的文件。我在一个标以此为filepath现在文件路径持有

filepath: "/samples/leads/Import_Leads_Sample.csv" 

我想这两者进行组合,形成一个网址。

let url = "http://example.com/public/samples/leads/Import_Leads_Sample.csv" 

回答

0

将文件路径存储在变量中并合并这两个变量。

let url = "http://example.com/public/"; 
let filepath = Object.filepath; // equals "/samples/leads/Import_Leads_Sample.csv" 

let finalUrl = url + filepath.substr(1); // substr(1) to remove the '/' and avoid having a final url with '//' in it 
+0

'Object {filepath:“/samples/leads/Import_Leads_Sample.csv”}'这是我从API获取的。在执行完下面的步骤之后,我得到'http://example.com/public/[object对象]' –

+0

因为在变量'filepath'中,您必须存储从API调用中获得的字符串。检查我的更新,现在'filepath'等于您的API响应对象中的字符串url。 – SrAxi

+0

@AkashM检查我的答案的更新。问题是你需要将url存储在一个变量中,而不是一个对象。因此,导航对象以检索字符串并将其存储在变量中。这就是我在我的回答中所做的,认为具有API响应的对象是“Object”。但是你没有提供完整的代码或任何东西,所以我尽我所能做到了最好。干杯! ;) – SrAxi