使用#include <stdio.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <time.h>
#include <cairo.h>
#include <stdlib.h>
typedef struct Timer {
gboolean running;
}*TimerP;
typedef struct TimerData {
TimerP timerPointer;
} *TimerDataP;
static void startTimerPressed (GtkWidget *widget, gpointer data, TimerDataP timerData) {
printf("TimerData Location: %p\n", timerData);
TimerP timer = timerData->timerPointer;
}
int main (int argc, char *argv[]) {
GtkWidget *startButton;
GtkWidget *window;
GtkWidget *grid;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 550, 200);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 20);
grid = gtk_grid_new();
gtk_grid_set_column_spacing(GTK_GRID(grid), 20);
gtk_grid_set_row_spacing(GTK_GRID(grid), 10);
gtk_container_add (GTK_CONTAINER (window), grid);
startButton = gtk_button_new_with_label ("Start");
TimerP timerPointer;
timerPointer = malloc(sizeof(struct Timer));
TimerDataP timerDataP;
timerDataP = malloc(sizeof(struct TimerData));
printf("TimerData Location: %p\n", timerDataP);
g_signal_connect (startButton, "clicked", G_CALLBACK (startTimerPressed), timerDataP);
gtk_grid_attach (GTK_GRID (grid), startButton, 0, 4, 1, 1);
gtk_widget_show_all(window);
gtk_main ();
}
时出现此错误:
原始例外:没有Http的提供者!
所以我将<md-icon>
添加到我的组件中并解决了它。所以我的问题是......为什么我需要在我的组件中添加HTTP_PROVIDERS
才能让HTTP_PROVIDERS
正常工作,即使我在我的应用中没有使用<md-icon>
呢?!
这是我的工作组件。从providers数组中删除HTTP_PROVIDERS
会引发上述错误。
HTTP_PROVIDERS
另外注意,此行将显示没有Http错误的图标,不需要import { Component } from '@angular/core';
import { HTTP_PROVIDERS } from '@angular/http';
import { MdIcon, MdIconRegistry } from '@angular2-material/icon';
@Component({
moduleId: module.id,
selector: 'foo-app',
template: `<md-icon>face</md-icon>`,
directives: [ MdIcon ],
providers: [MdIconRegistry, HTTP_PROVIDERS]
})
export class FooAppComponent {
title = 'Material 2 Foo App';
}
:
HTTP_PROVIDERS
答案 0 :(得分:3)
查看angular2-material的源代码,md-icon取决于angular2的Http
,这就是为什么你需要HTTP_PROVIDERS。
以下是来源的链接: https://github.com/angular/material2/blob/master/src/components/icon/icon.ts
在/src/components/icon/icon.ts中,该类需要MdIconRegistry
MdIcon
具有构造函数:
constructor(
private _element: ElementRef,
private _renderer: Renderer,
private _mdIconRegistry: MdIconRegistry) { }
且MdIconRegistry
要求Http
MdIconRegistry
具有构造函数:
constructor(private _http: Http) {}
我猜Http用于从网址获取图标?因此,如果你在源代码中挖掘几个级别,你可以在那里找到Http。
答案 1 :(得分:1)
Looking at the source显示MdIcon使用MdIconRegistry,它使用Http加载图标。这也在comment for MdIcon.
中提到这个库本身并不是自包含似乎仍然很奇怪,但现在看来它似乎就是这样。
答案 2 :(得分:0)
使用角度2.1.0和角度材质2.0.0-alpha.10执行以下操作:
import { MaterialModule } from '@angular/material';
@NgModule({
imports: [
MaterialModule.forRoot(),
]
})
答案 3 :(得分:0)
Angular 7
对于 me ,此错误的解决方案是MatIconRegistry
到我的APP模块上的提供者:
@NgModule({
declarations: [..],
imports: [
..,MatIconModule,
HttpClientModule,
..
],
providers:[ MatIconRegistry ],
exports: [..]
})
export class SomeModule { }