我有一些代码可以发布一些数据来创建数据记录。
它在服务中:
这是代码:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) { }
create() {
const postedData = { userid: 1, title: 'title here', body: 'body text' };
return this.http.post('https://jsonplaceholder.typicode.com/posts', postedData, httpOptions).subscribe(result => {
console.log(result);
}, error => console.log('There was an error: '));
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是...我该怎么做才能从用户登录时获得该网址的要求...我如何传递凭据?
我已经在Angular 6中完全设置了一个ag-grid,它在页面启动时可以正确显示所有rowData。但是,将项目添加到rowData时,ag-grid的显示不会更新。
我在以下StackBlitz链接中设置了这种情况:
https://stackblitz.com/edit/ag-grid-error?file=src/app/app.component.ts
我进行了设置,以便每次单击顶部的按钮时,都会向rowData添加一个项目,并将rowData记录到控制台(在右下方访问)。我遇到的问题是,当我单击按钮更新rowData时,ag-grid不会显示新项目。
有趣的是,如果您在编辑器中删除代码的任何部分并重新输入以更新显示,新项目将显示在ag-grid上。
预先感谢任何知道如何解决此问题的人。
我正在尝试在解析器中引发自定义错误,这些错误是我使用全局错误处理程序捕获的。我可以在组件中抛出错误,并且可以很好地解决问题,但是当我在解析器中抛出错误时,它们的类型将更改为标准Error类型。
这是一个正常运行的复制品:https : //stackblitz.com/edit/angular-gitter-vvgys6
设定
class DisplayableError extends Error {
// ...
}
@Injectable()
export class GlobalErrorHandlerService {
constructor() { }
handleError(error) {
console.log('GOT ERROR instance of DisplayableError', error instanceof DisplayableError);
}
}
Run Code Online (Sandbox Code Playgroud)
工作用法
在任何组件中,我都可以抛出一个错误,并且该错误被捕获在全局错误处理程序中,并且是的一个实例DisplayableError。
throw new DisplayableError('blah');
Run Code Online (Sandbox Code Playgroud)
用法破损
当我在解析器中抛出错误时,实例类型将更改为Error并instanceof DisplayableError返回false。
@Injectable()
export class StoreGetResolver implements Resolve<StoreModel> {
constructor(
private storeService: StoreService,
) { }
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<StoreModel> {
let storeId = route.paramMap.get('storeId');
return this.storeService.get(storeId)
.catch(error => Observable.throw(new DisplayableError('my …Run Code Online (Sandbox Code Playgroud) 为了尽可能简单地解决这个问题,这是我的方案.
1)我有一个父组件,它有一个ViewContainerRef动态加载父组件中的组件.对于我的用例,parent是一个空的holder页面,它根据一组变量动态地替换另一个页面.
<ng-template #dynamic></ng-template>
2)子组件有一个水平滚动div,看起来类似于以下内容:
<div id="carousel" (scroll)="onScroll($event)">
<!-- List of components -->
</div>
只要它与(scroll)侦听器一起滚动,它就会重新加载父组件,因此滚动位置总是会反弹回0,因为它已重新加载.
但是,如果我删除了(scroll)侦听器,则div会滚动而不会出现问题.问题是,我想根据水平滚动位置动态更改页面上的项目.
有没有人对嵌入式组件和滚动侦听器可能出现的问题有任何想法?非常感谢!
我已经尝试在StackOverflow上发布了多个方法,在角度6组件中使用jquery-ui,但它们都没有工作.例如,
我运行了npm install jquery jquery-ui来安装jquery和jquery-ui.
包含在angular.json中
"scripts":["node_modules/jquery/dist/jquery.js","node_modules/jquery-ui-dist/jquery-ui.js",
错误如下:
AppComponent_Host.ngfactory.js [sm]:1ERROR TypeError: jquery__WEBPACK_IMPORTED_MODULE_1__(...).slider is not a function
at AppComponent.push../src/app/app.component.ts.AppComponent.ngAfterContentInit (http:||localhost:4200/main.js:154:56)
at callProviderLifecycles (http:||localhost:4200/vendor.js:42663:18)
at callElementProvidersLifecycles (http:||localhost:4200/vendor.js:42644:13)
at callLifecycleHooksChildrenFirst (http:||localhost:4200/vendor.js:42634:29)
at checkAndUpdateView (http:||localhost:4200/vendor.js:43565:5)
at callWithDebugContext (http:||localhost:4200/vendor.js:44454:25)
at Object.debugCheckAndUpdateView [as checkAndUpdateView] (http:||localhost:4200/vendor.js:44132:12)
at ViewRef_.push../node_modules/@angular/core/fesm5/core.js.ViewRef_.detectChanges (http:||localhost:4200/vendor.js:41948:22)
at http:||localhost:4200/vendor.js:37684:63
at Array.forEach (native)
Run Code Online (Sandbox Code Playgroud)
的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Car Dealer</title>
</head>
<body>
<app-root></app-root>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
app.component.html
<div id="slider">
</div>
Run Code Online (Sandbox Code Playgroud)
app.component.ts
import { Component, AfterContentInit } from '@angular/core';
import * …Run Code Online (Sandbox Code Playgroud) 我使用Ionic Tabs Component生成了一个应用程序.
标签是交货,关于和联系.
然后我生成了一个页面细节.
我希望页面详细信息成为" 交付"选项卡的子项.
当我在详细信息页面上时,我正在浏览交付选项卡.
有人在Ionic Forum上提出了类似的问题
生成的目录结构:
- about
- contact
- deliveries
deliveries.module.ts
- details
details.module.ts
- tabs
tabs.module.ts
tabs.page.html
tabs.router.module.ts
app.module.ts
app-routing.module.ts
Run Code Online (Sandbox Code Playgroud)
这是生成的app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
];
@NgModule({
imports: [
RouterModule.forRoot(routes)
],
exports: [RouterModule]
}) …Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以混淆AnAngular 6(或7)应用程序的生产代码。生产代码是指在ng build --prod命令之后生成的dist文件夹。我见过一个名为Jscrambler的软件,但它不是免费的。我怎样才能做到这一点 ?
谢谢
我有一个表,其中每个表格单元格是一个组件的不同实例.根据数据(日期,文本,链接),我使用不同的组件.
由于这些组件有很多共同之处,我引入了一个TableCellMasterComponent,它由所有其他类型的表格单元扩展.
我的所有组件都具有相同的主机属性:
@Component({
selector: 'td[app-text-col]',
templateUrl: './text-col.component.html',
styleUrls: ['./text-col.component.css'],
host: {
"[hidden]": "col.deactivated"
},
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TextColComponent extends TableCellMasterComponent{
}
Run Code Online (Sandbox Code Playgroud)
是否有可能以某种方式将其移动到TableCellMasterComponent?
我也很想给他们所有人一个上下文菜单.但正如我所看到的,无法在Master中添加HTML.真的吗?
我可以将changeDetection移动到Master吗?
我几乎每天都在处理这个问题。我不明白这是怎么回事。
我在应用程序中使用反应形式,当我显示创建形式时,它运行良好。
但是,当我尝试显示编辑表单时,总是出现错误:
zone.js:192未捕获的错误:找不到路径为“ items-> 0-> content”的控件
我用下面的代码创建表单:
createFormGroup() {
return this.formBuilder.group({
items: this.formBuilder.array([this.createProductItems()]),
});
}
createProductItems() {
const productItems = [];
if (this.sourceProduct) {
this.sourceProduct.items.forEach(value => {
productItems.push(this.createProductItem());
});
}
return productItems;
}
Run Code Online (Sandbox Code Playgroud)
createProductItem方法a定义如下
createProductItem(): FormGroup {
return this.formBuilder.group({
content: ['', [Validators.required]],
quantity: ['', [Validators.required]]
});
}
Run Code Online (Sandbox Code Playgroud)
在我的模板中,我有以下内容html:
<div class="form-group row">
<label class="col-md-1 col-form-label label-main">{{"Items" | translate}}
<i (click)="addItem()" class="icon-button nb-plus-circled mr-1 fa-3x"></i>
</label>
<div class="col-md-9" formArrayName="items">
<div class="row"
*ngFor="let item of itemsArray.controls; let i = index;"> …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×9
typescript ×5
javascript ×3
ag-grid ×1
angular7 ×1
carousel ×1
components ×1
inheritance ×1
ionic4 ×1
jquery ×1
jquery-ui ×1
obfuscation ×1
rxjs ×1
security ×1
stackblitz ×1