我有剩下的api惠特/n代码,可以用<br>标签替换angular 6
这是我的代码:
{{x.deskripsi}}
Run Code Online (Sandbox Code Playgroud)
我尝试使用https://www.npmjs.com/package/angular-nl2br-filter
但是我不知道如何与{{}}标签内部绑定一起使用
我尝试使用此代码
<p ng-bind-html="x.deskripsi | nl2br"></p>
Run Code Online (Sandbox Code Playgroud)
但不起作用
有什么帮助吗?
之前感谢
我正在成功使用angular 2 安全导航操作符作为属性,文档说明属性路径,但方法路径的最佳方法是什么?
myObj?.myMethod().myProperty
Run Code Online (Sandbox Code Playgroud)
给出例外:
EXCEPTION:TypeError:无法在[{{myObj?.myMethod().myProperty}}中读取null的属性'myProperty'
在我的角度应用程序中,我有以下内容:
export class MyComponent {
subcompPath = "path-to-subcomp#SubcompClassName";
@ViewChild("placeholder", { read: ViewComponentRef }) placeholderRef: ViewComponentRef;
/* Constructor where Compiler, ComponentFactoryResolver are injected */
loadSubcomponent() {
let [path, componentName] = this.subcompPath.split("#");
(<any>window).System.import(path)
.then((module: any) => module[componentName])
.then((type: any) => {
return this._compiler.compileComponentAsync(type)
})
.then((factory: any) => {
let componentRef = this.placeholderRef.createComponent(factory, 0);
});
}
}
Run Code Online (Sandbox Code Playgroud)
我的子组件声明了提供者和东西,指令和管道.
而现在RC6又打破了一切.组件不能声明指令和管道,但它们必须位于声明组件的模块中.所以我必须加载SystemJS而不是组件本身而是模块.好的,然后我应该使用
return this._compiler.compileModuleAndAllComponentsAsync(type)
Run Code Online (Sandbox Code Playgroud)
很好,但是如何获得该特定组件的工厂参考?那个工厂就是我所需要的,placeholderRef想要它的createComponent方法,对吧?
我试图从github挖掘angular2源代码,但是它非常庞大,我应该尝试使用VS Code或者其他东西,使用intellisense,但我很懒...我应该从文档中读取这些内容,这些内容相当平淡无奇. angular.io这个特定的参数,它是没有路由器的组件和模块的延迟加载.
感谢任何帮助,我认为解决方案很容易应用,但没有官方文档很难找到.
无法去除ionic-2中的动态组件.在打字稿时,它会说异常
"通用类型'ComponentRef'需要1个类型的参数".
此外,在不使用ionic2的情况下使用相同的代码.非常感谢你的帮助.提前致谢.
class DynamicCmp {
_ref: ComponentRef;
_idx: number;
constructor(private resolver: ComponentResolver, private location: ViewContainerRef) { }
remove() {
this._ref.destroy();
}
add1() {
this.resolver.resolveComponent(DynamicCmp).then((factory: ComponentFactory<any>) => {
let ref = this.location.createComponent(factory, 0);
ref.instance._ref = ref;
ref.instance._idx = this._idx++;
});
}
}
Run Code Online (Sandbox Code Playgroud)
例外:TypeScript错误:....../home/home.ts(9,11):错误TS2314:通用类型'ComponentRef'需要1个类型的参数.
我有一个带有背景图片的画布。我想要可以在画布上移动的对象(按钮或 div)。
我找到了interact.js的完美解决方案。页面上的第一个示例(称为拖动)正是我想要实现的。获取画布上的位置,如果对象移到外面,它会自动回到里面。
但是,我已经在使用dragula对项目进行排序,并且只想保留一个用于拖放功能的库。添加另一个库会增加我的 web 应用程序的复杂性。
用 Dragula 实现这一目标“容易”吗?如果是,如何?
需要一个代码示例才能理解如何操作。
我有一个文本输入,我正在听取更改.
零件
name = new FormControl('',Validators.required);
ngOnInit() {
this.data = 'oldvalue';
this.checkName();
}
checkName() {
this.name.valueChanges.subscribe(val=>{
console.log(val);
this.data= "newvalue"; // updating Value
});
}
Run Code Online (Sandbox Code Playgroud)
HTML
<input name="name" formControlName="name">
Run Code Online (Sandbox Code Playgroud)
到目前为止我的尝试:
component.spec.ts
it('should test data field ', () => {
const fixture = TestBed.createComponent(UserComponent);
const app=fixture.debugElement.componentInstance;
const el = fixture.nativeElement.querySelector('input');
el.value ='something';
dispatchEvent(new Event(el));
fixture.detectChanges();
fixture.whenStable().then(()=>{expect(app.data).toBe('newvalue');
});
Run Code Online (Sandbox Code Playgroud)
问题: 即使填充了输入字段,也不会执行subscribe回调中的代码.
它总是显示:
预期'oldvalue'为'newvalue'.
我也尝试了setValue()方法,但它没有用.它永远不会进入订阅回调
app.name.setValue('vikas');
fixture.detectChanges();
fixture.whenStable().then(()=>{expect(app.data).toBe('newvalue');
Run Code Online (Sandbox Code Playgroud)
我在Angular 2测试和Angular2组件中引用了更新输入html字段 :测试表单输入值更改但没有运气:(
我错过了什么?
我将 angular 9 与 Angular Material 一起使用,并且通过实现 ControlValueAccessor 接口有一个自定义控件。一切正常。
当表单无效时,在我所有的提交按钮中,我调用 formGroup.markAllAsTouched 因为所有的角度材料字段都变为红色。通过这种方式,用户可以更好地了解哪些控件无效。
我需要用我的自定义控件实现相同的行为。怎么做?
我创建了一个 stackblitz 项目,以便更好地了解这里的情况
我有一个由多个组件组成的 angular2 应用程序,它在其模板中嵌入了(参数)不同的小 svg 文件。这个选择的原因是我需要与 svg 进行交互并操作 svg 文件的内部 DOM。另外我想引用一个 svg 文件,而不是在模板中的多个位置使用内联 svg,它在组件模板中更干净。
我的问题是这些 svg 文件没有被缓存在浏览器中,并且在加载包含多个组件(呈现这些 svg 文件)的页面时,我注意到在页面完成加载之前有一些小延迟。这远非最佳,如果我不能解决这个问题,我会考虑回到内联 svg。
我的目标是能够让组件模板指向一个 svg 文件,并且当这个组件第一次加载时,它不会从服务器发送,而是从浏览器缓存中检索。希望这将解决我遇到的延迟加载问题。我已经尝试在我的应用程序的根目录中定义一个 cache.manifest 文件(它定义了要缓存的不同 svgs),但是当组件加载时,服务器仍然在每次组件时发送 svgs(和 param.js)加载。!
这就是我构造一个组件模板的方式,它由 svg 符号组成,当我单击 svg 符号时,我会打开一个应包含相同符号的弹出窗口:
<div>
<!--Header-->
<div>{{ name }}</div>
<!--Actual svg symbol Object-param style-->
<div class="symbolIcon"(mouseup)="onMouseUp()" (mousedown)="onMouseDown()" >
<object type="image/svg+xml" data="app/mySymbol.svg" >
<param name='Activate' value={{activate}} />
<param name='Status' value={{status}} />
</object>
</div>
</div>
<!--Placeholder for Popup-->
<modal-popup *ngIf="loadPopup" (command)="popupCmd($event);">
<!--Symbol to be placed on Popup (same as in template above)-->
<div class="modal-startstop-symbol"> …Run Code Online (Sandbox Code Playgroud) 在Angular 2中,我有一个带有模板的组件。
在组件TypeScript代码中,我创建了一个Reactive Extensions Observable(items$),并在ngFor带有异步管道的模板的-directive中使用它。
这样,我不必担心自己订阅和取消订阅。
<div *ngFor="let item of items$ | async"></div>
...
</div>
Run Code Online (Sandbox Code Playgroud)
现在,从组件代码中,我想访问项目列表,但不订阅它。模板是否有办法退还或引用项目列表?
我正在尝试访问ngOnit中的rest api,如下所示:-
ngOnInit(): void {
this.myModel = new myModel ();
Observable.forkJoin(
this.myService.getdata(),
this.myService2.getData2(id)
).subscribe(
data => {
this.data1 = data[0];
this.data2 = data[1];
},
err => { console.error(err); },
() => {
//other work
});
}
Run Code Online (Sandbox Code Playgroud)
在执行上述代码时,我得到以下错误:-
错误错误:ExpressionChangedAfterItHasBeenCheckedError:检查表达式后,表达式已更改。先前的值:“ false”。当前值:“ true”
angular ×8
html ×2
rxjs ×2
angular6 ×1
caching ×1
dragula ×1
dynamic ×1
interact.js ×1
ionic2 ×1
jasmine ×1
javascript ×1
observable ×1
svg ×1
typescript ×1
unit-testing ×1