这是我的设置:
import {bootstrap} from 'angular2/platform/browser';
import {Component} from 'angular2/core';
import {LocationStrategy, APP_BASE_HREF, HashLocationStrategy, ROUTER_DIRECTIVES, Router, RouteConfig, ROUTER_PROVIDERS} from 'angular2/router';
import {HomeComponent} from "../components/HomeComponent";
import {provide} from "angular2/core";
@Component({
selector: 'app',
template: `<a [routerLink]="['/Home']">Home</a>
<router-outlet></router-outlet>`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{ path: '/', component: HomeComponent, name: 'HomeComponent' }
])
class RootComponent {
constructor(router:Router) {
}
}
bootstrap(RootComponent, [ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: HashLocationStrategy})
, provide(APP_BASE_HREF, {useValue: '/'})]);
Run Code Online (Sandbox Code Playgroud)
我一直得到这个错误,任何帮助表示赞赏
我正在使用最新的Beta.0
问候
肖恩
这是问题:我有一个服务在构造函数中发出HTTP请求:
constructor(public http: Http, public geolocation: Geolocation) {
this.http = http;
this.geolocation = geolocation;
//Http request... this will set variable forecast of the class when complete.
this.getForecast(16);
}Run Code Online (Sandbox Code Playgroud)
然后我在这样的组件中注入该服务:
constructor(public connector: ApiConnector) {
this.forecast = connector.forecast;
}Run Code Online (Sandbox Code Playgroud)
如果我尝试在组件装饰器上使用组件类的预测成员,就像我在这里一样:
@Component({
selector: 'app',
directives: [MainForecast, DailyForecast],
template: `
<main-forecast [main-weather]="forecast"></main-forecast>
<daily-forecast [weather-list]="forecast.list"></daily-forecast>
`,
})Run Code Online (Sandbox Code Playgroud)
我收到一个错误,"无法读取未定义的属性'列表'......"
是否有可能在组件构造函数中使用promises?
我有这个界面:
interface IInternalListener {
element: HTMLElement,
id: string,
type: string,
listener: EventListenerOrEventListenerObject,
useCapture: boolean
}
Run Code Online (Sandbox Code Playgroud)
我也想使用这个界面:
interface IListener {
element: HTMLElement,
id: string | number,
type: string,
listener: EventListenerOrEventListenerObject,
useCapture: boolean
}
Run Code Online (Sandbox Code Playgroud)
唯一的区别是 的类型id。我想采用 DRY(不要重复自己)。
如何在不复制粘贴的情况下创建它。映射类型似乎是可行的方法,但在这个答案中,他们映射了所有道具 - Typescript: how do you create a Copy of a type but change the property typeing
我只想改变一个道具。我怎样才能做到这一点?我不必使用映射类型,任何可行的解决方案都是公平的。
我有一个数组列表,看起来像:
[new Class1(), new Class2(), new Class1(), new Class1()]
Run Code Online (Sandbox Code Playgroud)
我想知道在数组列表中提取Class1实例数的最有效方法.
对于上面的例子,我想要答案3.
我使用的是Java版"1.7.0_79".
总NGINX初学者在这里.
我的日志目前看起来像:
92.21.236.47 - - [08/Jan/2017:00:48:10 +0000]"GET/HTTP/1.1"200 148" - ""Mozilla/5.0(Windows NT 10.0; WOW64; rv:50.0)Gecko/20100101火狐/ 50.0"
当我在默认的/etc/nginx/nginx.conf中添加以下行时
log_format main '$remote_addr - $remote_user xxx[$time_local]xxx '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
Run Code Online (Sandbox Code Playgroud)
(access_log和error_log行已存在于默认配置中,我将这些仅用于上下文).
然后我重启NGINX:
systemctl restart nginx
Run Code Online (Sandbox Code Playgroud)
我现在希望我的日志能够改变,特别是显示使用的xxx文字值.. xxx [$ time_local] xxx ..但我的改变没有任何区别.
如果我将log_format main更改为log_format组合,则服务器将不会重新启动.
在 ES6 中,我们可以这样做:
let myFunc = ({name}) => {
console.log(name)
}
myFunc({name:'fred'}) // => logs 'fred'
Run Code Online (Sandbox Code Playgroud)
但是我该如何处理这样的嵌套属性:
myFunc({event:{target:{name:'fred'}}}) // => I want it to log 'fred'
Run Code Online (Sandbox Code Playgroud)
myFunc 应该是什么样子才能记录“fred”?
我无法更改传入的对象。我希望使用解构来实现这种或其他一些合适的 ES6 方法。
我正在使用 Angular 5。
热重载大约需要 8 秒,这是合理的(虽然不是很好)但是有什么方法可以配置它以便我可以调整它以使其更快?
担心随着应用程序的增长它会变得更慢。谢谢。
我在我的应用程序中包含了一个 Bootstrap 主题。我已将文件复制到 src 文件夹(与 style.css 相同级别)并将其添加为 angular.json 中的最后一个 css,如下所示:
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/WFRH-Web",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config"
],
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"node_modules/bootstrap-select/dist/css/bootstrap-select.min.css",
"src/theme_minco.min.css"
Run Code Online (Sandbox Code Playgroud)
并且样式在开发模式下正常工作,但在部署我的应用程序后它们不起作用。
我用于部署的步骤是:
1) ng build --prod
2) firebase deploy
Run Code Online (Sandbox Code Playgroud)
我也试过在styles.css中使用include,只在angular.json中保留styles.css,如下所示:
@import "theme_minco.min.css";
Run Code Online (Sandbox Code Playgroud)
无济于事,因为它也不起作用(它仅适用于开发人员)。
请问有什么帮助吗?
我已经用 编写了我的第一个角度应用程序Angular 6。
我还没有编写任何测试,但在生成components和时自动创建了一些默认测试文件services。
当我使用运行自动生成的测试时
ng test
Run Code Online (Sandbox Code Playgroud)
它给出了太多的错误。其中一个错误就像
ChangeAvatarModalComponent should create
Failed: Template parse errors:
There is no directive with "exportAs" set to "ngForm" ("
<div class="modal-body">
<form [formGroup]="changeAvatarForm" id="avatar-form" [ERROR ->]#formDir="ngForm" (submit)="onSubmit()">
<div class="row">
<div class="col-md-12">
"): ng:///DynamicTestModule/ChangeAvatarModalComponent.html@8:56
Can't bind to 'formGroup' since it isn't a known property of 'form'. ("
<div class="modal-body">
Run Code Online (Sandbox Code Playgroud)
我有一个帐户模块,其中包含ChangeAvatarModalComponent。
我在account.module.ts中有以下几行
@NgModule({
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
RouterModule.forChild(AccountRoutes),
NgbModule
],
declarations: [
ChangeAvatarModalComponent
], …Run Code Online (Sandbox Code Playgroud) 我的 Angular 应用程序的服务中有以下代码:
const subby = Subject.create(observer, observable)
Run Code Online (Sandbox Code Playgroud)
但我的 IDE 正确标记Subject.create为已弃用。我应该用什么代替谢谢?我尝试过new Subject(observer, observable),但没有快乐。TIA。
RxJS版本:6.4.0
角度版本:7.2
angular ×6
javascript ×2
typescript ×2
angular-cli ×1
angular-test ×1
angular6 ×1
css ×1
deployment ×1
ecmascript-6 ×1
hot-reload ×1
http ×1
java ×1
java-7 ×1
livereload ×1
nginx ×1
promise ×1
rxjs ×1