我是使用PrimeNG的新手,我需要一个确认对话框.我阅读了有关确认对话框的文档,并在我的组件上实现了它.
我-component.ts
import { ConfirmDialogModule, ConfirmationService } from 'primeng/primeng';
Run Code Online (Sandbox Code Playgroud)
我-component.html
<p-confirmDialog header="Order Confirmation" icon="fa fa-question-circle" width="425" #cd>
<p-footer>
<button type="button" pButton icon="fa-close" label="No" (click)="cd.reject()"></button>
<button type="button" pButton icon="fa-check" label="Yes" (click)="cd.accept()"></button>
</p-footer>
</p-confirmDialog>
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { ConfirmDialogModule, ConfirmationService } from 'primeng/primeng';
@NgModule({
declarations: [
],
imports: [
BrowserModule,
ConfirmDialogModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
AppRoutingModule
],
providers: [ConfirmationService],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
我遗漏的任何东西都会引发错误?请赐教.
上次我使用Angular2时,指令仍然存在,但现在在app.modules.ts中有所谓的声明.问题是,如果我要仅在特定组件中使用指令而不在主要组件上,我该怎么做?
customers.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-customers',
templateUrl: 'app/customer/customers.component.html'
})
export class CustomersComponent {
customers = [
{ id: 1, name: 'Mix'},
{ id: 2, name: 'Ian'},
{ id: 3, name: 'Aniel'},
{ id: 4, name: 'Jess'},
{ id: 5, name: 'Jusi'},
];
}
Run Code Online (Sandbox Code Playgroud)
customer.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-customer',
templateUrl: 'app/customer/customer.component.html'
})
export class CustomerComponent {
@Input() customer: {id: number, name: string};
myColor = 'gray';
}
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { NgModule …
Run Code Online (Sandbox Code Playgroud) 我创建了一个User接口,用于从ngModel中输入一些值.看看这个.
user.ts
export class User{
_id: String;
username: String;
password: String;
firstname: String;
lastname: String;
gender: String;
address: String;
contact: Number;
email?: String;
}
Run Code Online (Sandbox Code Playgroud)
ngModel绑定的示例
<input type="text" [(ngModel)]="user.username" class="form-control" name="username" id="username" placeholder="Enter your Username" formControlName="username"/>
Run Code Online (Sandbox Code Playgroud)
控制台日志的输出
我想把结果变成一个json.我使用JSON.parse但弹出标题上的错误.如何将其转换为json对象?谢谢
我有这个输入类型编号,但我需要禁用框中的用户输入。向上和向下箭头应增加或减少显示的数字。
<td data-th="Quantity">
<input type="number" min="1" max="99" class="form-control text-center" value="{{cartItem.quantity}}" formControlName="quantity" #itemQuantity>
</td>
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它发挥作用?
我有这个购物车组件,用于从后端获取购物车数据.
import { Component, OnInit } from '@angular/core';
import { CartService } from './cart.service';
@Component({
selector: 'cart',
templateUrl: './cart.component.html',
styleUrls: ['./cart.component.css']
})
export class CartComponent implements OnInit{
carts: any;
cartItems: any;
totalPrice: Number;
constructor(private _cartService: CartService){};
ngOnInit(){
this.getItems();
}
getItems(){
this._cartService.getCartItems(localStorage.getItem('currentUserId'))
.subscribe((cart) => {
this.cartItems = cart.products;
this.totalPrice = cart.totalPrice;
this.carts = cart;
console.log(this.carts)
},
(err) => console.log(err));
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的对象值.
我将所有产品放在我的组件中显示的cartItems中,并使用*ngFor将其循环到我的模板中
<tbody *ngFor="let cartItem of cartItems">
Run Code Online (Sandbox Code Playgroud)
这是结果
现在我想更新一个项目的数量,按下删除按钮旁边的刷新按钮,然后它将只发送我按下刷新按钮到后端的产品详细信息.
有人可以帮我解决这个问题吗?