标签: angular2-template

Angular 2 Concat 和 Grunt 缩小

我喜欢使用 Grunt 来连接和缩小插件等.. 有人可以告诉我如何在 Angular 2 的 node_modules 上完成这项任务.. 我想最终得到 1 个缩小和连接的文件.. 我试过 webpack 等和 gulp教程,但没有一个能完成工作。

gruntjs grunt-contrib-concat angular2-template angular

6
推荐指数
0
解决办法
309
查看次数

当属性存在且为空时,使 Angular 2 组件输入“true”

考虑一个 Angular 2 组件,它的@Input意思是一个布尔值,它的存在表示true,不存在表示false。现在,我可能会使用自定义的 getter/setter 来管理它,或者通过一个函数来告诉我该属性是否存在:

@Component({
  selector:'foo',
  template:`<div [class.error]="hasError()">Hello world</div>`
})
class Foo {
  @Input() error:string;
  public hasError() {
    return error === '' || !!error;
  }
}
Run Code Online (Sandbox Code Playgroud)

然后我可以在另一个组件中使用它,如下所示:

<foo></foo> <!-- no error class -->
<foo error></foo> <!-- has error class -->
Run Code Online (Sandbox Code Playgroud)

我真正想做的是这个,但有相同的行为:

@Component({
  selector:'foo',
  template:`<div [class.error]="error">Hello world</div>`
})
class Foo {
  @Input() error:boolean;
}
Run Code Online (Sandbox Code Playgroud)

在我的第一个示例中,是否有一种通用模式可以在没有样板的情况下创建这种行为?

javascript angular2-template angular

6
推荐指数
1
解决办法
1492
查看次数

递归 Angular 2 HTML 绑定

这是我的问题,我想在 HTML 模板中包含一个按钮,该按钮链接到外部网站。但是,当读取 HTML 时,谷歌浏览器会说:

WARNING: sanitizing HTML stripped some content (see http://g.co/ng/security#xss).
Run Code Online (Sandbox Code Playgroud)

似乎 Angular 2 的 innerHTML 属性不允许 2 个递归 HTML 绑定。

这是我的代码:

<ion-col width-80 innerHtml="{{ slide.content + '<p><button round full (click)=`' 
+ slide.button.url +'`>'+slide.button.text+'</button>' }}"></ion-col>
Run Code Online (Sandbox Code Playgroud)

(click) 属性被删除,只(slide.button.text)显示为单个文本。

任何解决方案?

slide 是这样的:

{
    img: 'img/picture.png',
    content: `sometext`,
    button : {
        url: `http://www.foo.com`,
        text: `Site foo`
    }
}
Run Code Online (Sandbox Code Playgroud)

typescript ionic-framework ionic2 angular2-template angular

6
推荐指数
1
解决办法
1261
查看次数

如何检查是否在组件上触发了更改检测

在我的应用程序中,我想设置手动更改检测.为此,我将ChangeDetectionStrategry设置为OnPush,每当组件发生更改时,我使用detectChanges手动运行更改检测.

如果我在父组件上将ChangeDetectionStrategy设置为OnPush,根据我的理解,它将仅在父组件上运行一次更改检测,在子组件上只运行一次,即使我没有在子组件上将ChangeDetectionStrategy设置为OnPush.如果父组件有任何更改,我在父组件中运行detectChanges().如果子组件有任何变化,我在子组件中运行detectChanges().

请建议这是正确的方法吗?还是有更好的方法吗?

其次,有没有办法检查它是否按预期工作,并且没有对特定组件执行更改检测.

angular2-directives angular2-template angular2-changedetection angular

6
推荐指数
2
解决办法
3268
查看次数

Angular 2:即使导入了 FormsModule,也无法绑定到“ngModel”

Can't bind to 'ngModel' since it isn't a known property of 'input'.尽管我已经导入了FormsModule.

包.json:

"@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "^2.0.0",
Run Code Online (Sandbox Code Playgroud)

在主应用程序模块中:

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
...
@NgModule({
  bootstrap: [App],
  declarations: [
    App
  ],
  imports: [ // import Angular's modules
    BrowserModule,
    HttpModule,
    RouterModule,
    FormsModule,
    ReactiveFormsModule,
    NgaModule,
    PagesModule,
    routing
  ]
Run Code Online (Sandbox Code Playgroud)

这是我路由到组件的位置(pages.routes.ts):

import { NewProjectModule, BasicForm } from './new-project/new-project.module';
...
{ path: 'new-project', component: BasicForm },
Run Code Online (Sandbox Code Playgroud)

这是组件模块:

import { FormsModule } from '@angular/forms';
...
import { …
Run Code Online (Sandbox Code Playgroud)

angular2-forms angular2-template angular

6
推荐指数
1
解决办法
8745
查看次数

从组件 angular 2 获取 ng-template

我怎样才能得到 angular 2 中的元素?如果我在 html 中有这个

<ng-template #content let-c="close" let-d="dismiss">
  <div class="modal-header">Header</div>
   <div class="modal-body">Body</div>
  <div class="modal-footer">footer</div>
</ng-template>
Run Code Online (Sandbox Code Playgroud)

如果我使用按钮打开内容,我将它用于 ngBmodal ng-bootstrap 其工作 = 按钮

(click)="open(content,data.id)"
Run Code Online (Sandbox Code Playgroud)

然后我想在这种情况下从组件打开内容,我从其他页面重定向并打开内容

ngOnInit() {
    this.activatedRoute.queryParams.subscribe((params: Params) => {
        let id = params['id'];
        if(id != undefined){
          this.open('content',id);         
        }
      });
  }
open(content, id) {
    this.dataModal = {};
    this.getDataModal(id);

    this.mr = this.modalService.open(content, { size: 'lg' });
  }
Run Code Online (Sandbox Code Playgroud)

模式打开但不使用 html,我尝试 afterviewinit 来获取 #content 它不起作用谢谢,对不起我的英语:v

angular2-directives angular2-template ng-bootstrap

6
推荐指数
1
解决办法
6761
查看次数

如何在 Angular 2 中动态添加样式表?

有没有办法<style></style>在 Angular2 中动态添加样式表 url 或动态?

例如,如果我的变量是isModalOpenedis true,我想向根组件之外的几个元素添加一些 CSS。喜欢body或html。

可以使用 DOM 或 jQuery 来完成此操作,但我想使用 Angular 2 来完成此操作。

可能的 ?

谢谢

html javascript css angular2-template angular

6
推荐指数
2
解决办法
3791
查看次数

如何在 Angular 选择元素上使用默认的“请选择”选项并使用 null 值进行验证?

我在 Angular ngFor 循环中有一个选择 HTML 元素:

<select formControlName="type" required>
  <option *ngFor="let type of typeList" [ngValue]="type.value">{{ type.caption }}</option>
</select>
Run Code Online (Sandbox Code Playgroud)

在 Internet Explorer 中,加载模板时会选择列表中的第一项,但它的值未在表单控件中设置,因此会导致“必需”验证错误,直到在列表中选择另一个值为止。我想要一个具有空值的“请选择”选项,以防止发生这种情况。

这适用于使用或不使用 TypeScript 的 Angular 2+

html angular2-forms angular2-template angular

6
推荐指数
1
解决办法
5663
查看次数

当焦点失去放置在表中的输入时如何触发“focusout”事件?

我有一个放置table位置:input

<tr *ngFor="let persons of ReceivedData">
  <td *ngFor="let person of persons">

    <div *ngIf="person.personId === editRowId && person.editable === true ">
        <input type="number" [(ngModel)]="person.CarCount" 
               (focusout)="focusOutFunction()"/>
    </div>                            
    <div *ngIf="person.editable === false " (click)="toggle(person)">
        {{ person.CarCount ? person.CarCount : '-' }}
    </div>

  </td>
<tr>
Run Code Online (Sandbox Code Playgroud)

但该focusout事件并未被解雇。这是处理该函数的方法focusout:

focusOutFunction() {        
}
Run Code Online (Sandbox Code Playgroud)

有趣的是,当未放置在内部时,focusout效果很好:inputtable

<input type="number" (focusout)="focusOutFunction()" />
Run Code Online (Sandbox Code Playgroud)

当我聚焦在桌子内部时如何触发事件?

html input lost-focus angular2-template angular

6
推荐指数
1
解决办法
1万
查看次数

当使用 container="body" 滚动主页时​​,ngx boostrap popover 不会随按钮移动

我正在根据本文档使用 ngx boostrap popover

我需要使用,container="body"因为没有这个,主体样式会影响我的弹出框并被剪掉。但是,在添加此属性后,我遇到了一个新问题。当我单击按钮时,弹出窗口会显示在按钮的后面,这很好。但是,当我滚动主页时​​,弹出框不会随与其关联的按钮一起移动,因此进入分离状态,然后看起来很奇怪。我该如何解决这个问题?

bootstrap-popover angular2-template ngx-bootstrap angular

6
推荐指数
0
解决办法
486
查看次数