直到 5 分钟前它才工作没有意义......这是组件
import { Component, OnInit } from '@angular/core';
import {Osobaa} from '../osobaa';
import { Osoba } from '../osoba';
import {OsobaService} from '../osoba.service';
@Component({
selector: 'app-form-add',
templateUrl: './form-add.component.html',
styleUrls: ['./form-add.component.css']
})
export class FormAddComponent implements OnInit {
osoba : Osobaa;
constructor() { }
ngOnInit() { }
}
Run Code Online (Sandbox Code Playgroud)
这是主要的 app.module.ts
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import {FormsModule} from "@angular/forms";
import { AppComponent } from "./app.component";
import { HeaderComponent } from "./header/header.component";
import { …
Run Code Online (Sandbox Code Playgroud) 你好,我通过$ injector服务有一些依赖注入的问题.
我是棱角分明的新手,所以我将从IoC容器的角度解释我是如何看待它的.
首先关闭问题:$ injector无法解决$ state.
core.js
(function() {
'use strict';
angular.module('app.core',['ui.router'])
.config(function($stateProvider,$state){
// ......
});
}());
Run Code Online (Sandbox Code Playgroud)
这是错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module app.core due to:
Error: [$injector:unpr] Unknown provider: $state
Run Code Online (Sandbox Code Playgroud)
我不认为堆栈跟踪在这里有很多相关性...但是,以防万一我将它发布在问题的底部:
Index.html:我只是想显示我引用我的.js文件的位置和顺序.
<head>
.... <!-- pointing out that my .js are not here -->
</head>
<body>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="components/core/lib/core.js"></script>
**<!-- relevant to the EDIT part below -->
<script src="components/something/something.js"></script>**
</body>
Run Code Online (Sandbox Code Playgroud)
据我了解angular的供应商食谱:
$stateProvider …
Run Code Online (Sandbox Code Playgroud) 我正在尝试读取json github服务,但出现错误NullInjectorError:没有Http的提供程序!
我已经在所有代码中添加了提供程序,但是它无法正常工作,我不知道是什么导致了错误,但是知道它在哪里发生,我需要一些可以帮助理解导致此错误的原因的人
import { Injectable } from '@angular/core';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule, Http, JsonpModule} from '@angular/http';
import { Observable} from 'rxjs';
import 'rxjs/add/operator/map';
@NgModule({
imports: [
BrowserModule,
HttpModule,
JsonpModule,
]
})
@Injectable({
providedIn:'root'
})
export class GithubService{
constructor(private http:Http){
}
getUser(){
const searchText ="js";
const url = "http://api.github.com/search/users?q="+searchText;
this.http.get(url).subscribe(
res=> {
const data=res.json();
console.log(data);
return data;
}
)
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
AppComponent.html:7 ERROR NullInjectorError: StaticInjectorError(AppModule)[GithubService -> Http]:
StaticInjectorError(Platform: …
Run Code Online (Sandbox Code Playgroud) 当我运行我的 Angular 8 应用程序的 prod 版本时,我在控制台中收到此错误。构建运行良好,我已经在我的提供者中包含了所有服务。
我已经运行了以下命令,但没有收到任何错误。
ng build --prod --optimization=false
有什么办法可以判断什么是失败的?即使我注释掉所有提供程序(预计构建失败),我仍然没有收到任何错误。
请让我知道我可以/应该提供哪些其他信息来帮助您。谢谢!
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS, HttpClient } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { NavMenuComponent } from './nav-menu/nav-menu.component';
//a bunch more components...
import { AccountModule } …
Run Code Online (Sandbox Code Playgroud)