我昨天才刚开始学习Angular,所以如果我缺少明显的东西,我深表歉意,但是我试图在app.component.html上显示一个组件,但是它没有出现。
我尝试显示的组件的TS文件:
import { Component, OnInit } from '@angular/core';
import { ImageService } from '../shared/image.service';
@Component({
selector: 'image-list',
templateUrl: './image-list.component.html',
styleUrls: ['./image-list.component.css']
})
export class ImageListComponent implements OnInit {
images: any[];
constructor(private _imageService : ImageService ) { }
searchImages(query : string)
{
return this._imageService.getImage(query).subscribe
(
data => console.log(data),
error => console.log(error),
() => console.log("Request Completed!")
);
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
image-list.component.html:
<button>Find Images</button>
Run Code Online (Sandbox Code Playgroud)
app.component.html:
<image-list></image-list>
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import …Run Code Online (Sandbox Code Playgroud) 在Angular 6中,现在我想我了解如何制作和使用i18n文件(例如https://angular.io/guide/i18n),我想知道有关维护这些文件的信息。如果我进入并更改html,据我所知,我将不得不使用该ng xi18n命令重新生成messages.xml文件,这意味着我将需要将该文件重新翻译为其他语言,或者至少进行某种视觉匹配,因此我可以将某些div标记的内容从旧的,已翻译的文件移至新位置,并移至新文件中。维护更改似乎有很多开销,我希望我缺少一些东西,但这是维护文件的预期工作流程吗?以下是正确的[我希望不是],还是我不知道有更好的方法?
创建:
ng xi18n命令生成messages.xlf保养:
ng xi18n命令重新生成messages.xlf我是否缺少命令或工具,可以帮助我匹配放置在i18n标记(例如i18n="@@myUniqueTag")中的持久性ID,以便我可以将翻译后的目标(例如<target>my translated content</target>)自动移动到新文件?还是我真的必须手动将所有目标移动到新文件并将它们与每个源标签匹配?
最近,当我们想要使用jenkins将相同的角度构建(dist)部署到多个环境(这意味着不同的后端URL)时,我们遇到了这种情况.
'ng build --configuration $ENV' (angular-6) with backend url mentioned in 'src/environment/environment.$ENV.ts'显然不是我们的解决方案,因为这意味着创建特定于环境的多个构建.我正在浏览angular6 docs->组件交互部分,特别是“父级调用@ViewChild()”。它说-在Angular显示父视图之后,计时器组件才可用。因此最初显示为0秒。但是,当我尝试在ngAfterViewInit之外使用它时,它工作正常。见下文:
seconds() { return this.timerComponent.seconds; }
ngAfterViewInit() {
// Redefine `seconds()` to get from the `CountdownTimerComponent.seconds` ...
// but wait a tick first to avoid one-time devMode
// unidirectional-data-flow-violation error
// setTimeout(() => this.seconds = () => this.timerComponent.seconds, 0);
}
Run Code Online (Sandbox Code Playgroud)
此外,他们还提到要在同一周期内更新父级视图之前要稍等片刻,以避免编译器错误,但我也能够做到这一点。见下文:
seconds() { return 0; }
ngAfterViewInit() {
// Redefine `seconds()` to get from the `CountdownTimerComponent.seconds` ...
// but wait a tick first to avoid one-time devMode
// unidirectional-data-flow-violation error
// setTimeout(() => this.seconds = () => this.timerComponent.seconds, 0); …Run Code Online (Sandbox Code Playgroud) The latest Material documentation says the following..
If you want to close a custom snack-bar that was opened via openFromComponent, from within the component itself, you can inject the MatSnackBarRef.
but they don't show you how to do it.
In their example, they nest a component within the same .ts file as the calling module, and they don't show the ref being passed in. But since I want to use a more centralized approach, I have created a new module …
我尚未在互联网上找到解决方案。
Angular带来了类似的Github Issue,但是在那里找不到任何解决方案。
我已经将脚本文件添加到angular.json中,例如(在构建和测试范围中):
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": [
"src/assets/plugins/jquery/jquery-1.11.3.min.js",
"src/assets/plugins/jquery-ui-1.11.4.custom/jquery-ui.min.js",
"src/assets/plugins/bootstrap/js/bootstrap.min.js",
"src/assets/plugins/owl-carousel/owl.carousel.min.js",
"src/assets/plugins/bootstrap-select/js/bootstrap-select.min.js",
"src/assets/js/jquery.subscribe-better.js",
"src/assets/js/moment-with-locales.min.js",
"src/assets/plugins/countdown/jquery.plugin.min.js",
"src/assets/plugins/countdown/jquery.countdown.min.js",
"src/assets/js/theme.js"
]
Run Code Online (Sandbox Code Playgroud)
我正在获取CSS样式,但是某些脚本无法正常工作。
有什么办法吗?
请通过链接(https://ng-select.github.io/ng-select#/multiselect-checkbox)来了解ng-select多选复选框。
我试图在我的angular 6应用程序中使用ng-select “组选择子项”。
我在使用ng-select “组选择子项”和“反应式表单”而不是模板驱动的表单时遇到问题。
我已经厌倦了
<ng-select
[items]="userGroupsList"
[multiple]="true"
bindLabel="name"
groupBy="gender"
[selectableGroup]="true"
[selectableGroupAsModel]="false"
[closeOnSelect]="false"
bindValue="id"
formControlName="userGroups" placeholder="Select a user group">
<ng-template ng-optgroup-tmp let-item="item" let-item$="item$" let-index="index">
<input id="item-{{index}}" type="checkbox" [(ngModel)]="" formControlName="userGroupParent"/> {{item.gender | uppercase}}
</ng-template>
<ng-template ng-option-tmp let-item="item" let-item$="item$" let-index="index">
<input id="item-{{index}}" type="checkbox" [(ngModel)]="" formControlName="userGroupChild"/> {{item.name}}
</ng-template>
</ng-select>
Run Code Online (Sandbox Code Playgroud)
我已经使用了multiselect-checkbox的相同数据-[items] =“ userGroupsList”
https://github.com/ng-select/ng-select/blob/master/demo/app/shared/data.service.ts-getMockPeople()具有数据
所以在这里我可以在输入中使用[[ngModel)]以及formControlName,如示例中所示,当选择父元素时,如何选择子元素
请帮忙....!
到目前为止,我有一些不应运行的单元测试,是否可以跳过它们?除了在要运行的程序上使用fdescribe之外。
我在创建关于用户的第六个角度的CRUD应用程序时,尝试添加新用户时出现以下错误:
这是我得到的错误:
core.js:12301 ERROR TypeError: Cannot read property 'toLowerCase' of undefined
at HttpXsrfInterceptor.push../node_modules/@angular/common/fesm5/http.js.HttpXsrfInterceptor.intercept (http.js:1718)
at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http.js:1134)
at HttpInterceptingHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptingHandler.handle (http.js:1769)
at MergeMapSubscriber.project (http.js:974)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext (mergeMap.js:61)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next (mergeMap.js:51)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54)
at Observable._subscribe (scalar.js:5)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:43)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:29)
Run Code Online (Sandbox Code Playgroud)
这是添加用户组件html:
<div class="container add-user">
<div class="col-md-6">
<h2 class="text-center">Add User</h2>
<form [formGroup]="addForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" formControlName="email" placeholder="Email" name="email" class="form-control" id="email">
</div>
<div class="form-group">
<label for="firstName">First Name:</label>
<input formControlName="firstName" placeholder="First Name" name="firstName" class="form-control" id="firstName">
</div>
<div …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×5
javascript ×3
angular-i18n ×1
angular5 ×1
css ×1
html ×1
html5 ×1
recaptcha ×1
reference ×1
snackbar ×1
typescript ×1
zone.js ×1