我有一个Repository.cs包含接口的文件及其实现如下:
public interface IRepository
{
IEnumerable<City> Cities { get; }
void AddCity(City newCity);
}
public class MemoryRepository : IRepository
{
private List<City> cities = new List<City> {
new City { Name = "London", Country = "UK", Population = 8539000},
new City { Name = "New York", Country = "USA", Population = 8406000 },
new City { Name = "San Jose", Country = "USA", Population = 998537 },
new City { Name = "Paris", Country = "France", Population = …Run Code Online (Sandbox Code Playgroud) 我正在尝试将现有应用程序从使用更改Http为使用HttpClient,但是我有一个错误.
因此,在我的服务中,您现在可以看到新代码与已注释掉的旧代码:
constructor(
// private http: Http
private http: HttpClient
) { }
getSidebar() {
// return this.http.get('http://localhost:3000/sidebar/edit-sidebar')
// .map(res => res.json());
return this.http.get('http://localhost:3000/sidebar/edit-sidebar');
}
Run Code Online (Sandbox Code Playgroud)
在我,page.component.ts我有这个
this.sidebarService.getSidebar().subscribe(sidebar => {
this.sidebar = sidebar.content; // this does not work now
});
Run Code Online (Sandbox Code Playgroud)
但是对于我评论过的行,我现在得到了这个错误:
Property 'content'
does not exist on type 'Object'.
Run Code Online (Sandbox Code Playgroud)
但是,如果我console.log(sidebar)得到以下内容:
{_id: "59dde326c7590a27a033fdec", content: "<h1>sidebar here</h1>"}
Run Code Online (Sandbox Code Playgroud)
那么问题是什么?
再一次,Http有效,但HttpClient没有.
说我有这个:
<div class="somediv"></div>
<div class="somediv"></div>
<div class="somediv"></div>
<div class="somediv"></div>
<div class="somediv"></div>
<div class="somediv"></div>
Run Code Online (Sandbox Code Playgroud)
如何将每2个div包装到一个带有“ newdiv”类的新div中?
我有这个领域 app.component.ts
front: boolean = true;
Run Code Online (Sandbox Code Playgroud)
我正在显示这个组件模板 app.component.html
<app-navbar></app-navbar>
Run Code Online (Sandbox Code Playgroud)
那行得通,但我想根据 的值显示该组件(或不显示)front,所以我尝试了这样的操作,但它不起作用:
<*ngIf="front" app-navbar></app-navbar>
Run Code Online (Sandbox Code Playgroud)
如何实现这一目标?
我显示了一堆li,我从Web服务中获得的链接,这些链接中有title和slug财产.
问题是,我不想显示li,如果slug属性home,但是*ngIf指令不是让我的代码中的差异:
<ng-container *ngFor="let page of pages">
<li *ngIf="page.slug!==home">
<a routerLink="{{ page.slug }}">{{ page.title }}</a>
</li>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
我得到的所有页面,包括一个用slug的home.我怎么能避免这种情况?