Angular2:组件输入中的转义字符(Angular2: Escape character in component's input)
我有以下代码:
我已经尝试了许多东西( '' , \' , \\' , \'' ,......)以逃避' in,但我没有设法做到这一点。 我怎样才能做到这一点 ?
I have the following code :
I have tried many things ('', \', \\', \'', ...)to escape the ' in, but I didn't manage to do it. How can I do this ?
原文:https://stackoverflow.com/questions/40383532
更新时间:2020-02-18 08:35
最满意答案
似乎title是一个组件属性,因此它需要一个变量或一个字符串。 我假设正确的语法是:
在之前和之后添加单引号
It seems that title is a component property, hence it expects a variable or a string. I assume the correct syntax would be:
Adding a single quote before and after
相关问答
实际上,在定义@Ouput ,这意味着您希望组件发出事件 click.emit(null);
您的代码有点奇怪的是,您尝试在外部管理组件的内部事件。 所以我认为你的组件中不需要这个Output ...... 使用以下代码,您希望处理父组件中组件的click事件。 所以setText方法将是这个父组件中的一个(不是子组件中的一个)。
如果要与mybutton组件交互以在click事件上更新其按钮标
...
它不能确定你的字符串在哪里结束。 在规范中很好地告诉解决方案: 包含单引号的字符串文字用两个单引号表示,例如:'文字'的'。 你的情况意味着: ...where person.name='Andy''s'
It cannot figure out where you string literal ends. Solution is nicely told in specification: A string literal that includes a single quote is repr
...
看起来你没有告诉PostsComponent有关SpinnerComponent的信息 import {Component, OnInit} from 'angular2/core';
import {HTTP_PROVIDERS} from 'angular2/http';
import {PostsService} from './posts.service';
import {SpinnerComponent} from './spinner.component.ts'
@Compone
...
我不确定这是否有效。 但这是我解决问题的方法。 我希望它对你有用。 用这个替换输入控件的价格 -
[(ngModel)]="hero.price"
placeholder="Pristine Price"
[ngFormControl]="myForm.find('price')"
(keypress)="showErrorIfNotANumber($event)"
/>
然后添加此标
...
总之,你不能。 你必须隐藏组件if !data ,这样你的局部变量#test1R仍然会被设置。
然后在ngOnInit() test1内进行null检查以避免异常。 如果您只能在设置数据后执行某些代码,请执行以下操作: 在test1组件中将数据声明为输入: export class Test1 {
@Input() data: any;
}
通过每次值改变时将其声明为@Input
...
用这个 : ng-pattern="/^[a-zA-Z]*$/" My fix was to do it in my component firstName: ['', Validators.pattern('^[a-zA-Z \-\']+')],
似乎title是一个组件属性,因此它需要一个变量或一个字符串。 我假设正确的语法是:
在之前和之后添加单引号 It seems that title is a component property, hence it expects a variable or a string. I assume the correct syntax would be:
...
看到完整的代码将是有益的,但无论如何...... 您可以尝试将微调器移回修复模块,然后从应用程序模块中将其导入。 我使用单独的(在你的情况下它将是第三个)'共享'模块,其中常见功能坐在这里,所以每个其他模块可以从那里导入它。 Seeing the full code would be beneficial but anyway... You can try to move spinner back to repair module and import it from there in the a
...
我认为你可以利用这样的东西: this.compiler.resolveComponent(MyInputComponent).then((factory: ComponentFactory) => {
let component = this.target.createComponent(factory);
component.instance.field = this.field;
});
另请参见示例https://plnkr.co/edit/bdGYvTf8y9LE
...
使用@ContentChild()或@ContentChildren()您只能通过将这些组件或指令的类型作为参数传递来查询组件和指令,或者您可以查询模板变量。 如果你有
`
然后你可以查询div @ContentChild('someVar') ElementRef someVar;
如果您不希望组件的用户要求使用元素包装内容并添加特定模板变量,则可以使用
...