我有以下代码出于演示目的,显示了一个简单的带有错误消息和提交按钮的表格行:
<form [ngFormOptions]="{updateOn: 'submit'}">
<tid-form-row>
<label tid-ui-label for="temperatureInput">Temperature:</label>
<input [tid-ui-input]="{required: true}" id="temperatureInput" name="temperatureName" placeholder="20,4"
[(ngModel)]="temperatureModel" #temperature="ngModel" [tidDigits]="{integer: 2, fraction: 1}" required>
<ng-template #hint>
<small tid-ui-hint>The yellow color indicates that this field is required.</small>
</ng-template>
<div tid-ui-error *ngIf="temperature.invalid && (temperature.dirty || temperature.touched); else hint">
<span *ngIf="temperature?.errors.required">Field is required.</span>
<span *ngIf="temperature?.errors.tidDigits">Must be max 2 integer digits and max 1 fraction digit.</span>
</div>
</tid-form-row>
<tid-button type="submit">Check validation</tid-button>
</form>
Run Code Online (Sandbox Code Playgroud)
这里tidDigits是一个自定义的ValidatorDirective与此ValidatorFactory:
export function digitsValidator(config: any): ValidatorFn {
return (control: …Run Code Online (Sandbox Code Playgroud) 所以,我有一个Jhipster生成的应用程序.
在其中我们有许多实体,前端和后端都有"默认"方法
其中一个方法是create,在本例中是实体ActivePharmaIng,这是角度服务类中的代码:
create(activePharmaIng: ActivePharmaIng): Observable<ActivePharmaIng> {
const copy = this.convert(activePharmaIng);
return this.http.post(this.resourceUrl, copy).map((res: Response) => {
const jsonResponse = res.json();
return this.convertItemFromServer(jsonResponse);
});
}
Run Code Online (Sandbox Code Playgroud)
所以,这个代码就像它在实体区域中使用的魅力一样,但是,当我尝试在一个模态中重用它时,我从一个用(单击)调用的函数调用它,该函数的代码:
saveNewApi(api: ActivePharmaIng) {
this.activePharmaIngDTO.api = this.activePharmaIng;
this.activePharmaIngService.create(api);
this.show = false;
}
Run Code Online (Sandbox Code Playgroud)
在第二行中我们可以看到创建调用,在调试时我看到函数被无缝调用,并且只是在尝试执行调用后直接跳转到create函数
我没有任何错误消息的痕迹,没有使用IntelliJ调试,不是在谷歌开发人员工具栏中,在控制台和网络区域尝试,而不是单个消息.它只是跳转到下一行,这是一个布尔值,当设置为false时会隐藏表单的某些div:
我的页面上有 Select2 Javascript 小部件。
$('#order_address_select').select2({
placeholder: "Select adress",
ajax: {
url: '<?=Yii::app()->getBaseUrl(true)?>/order/getplacemarklist',
dataType: 'json',
},
tags: true,
});
Run Code Online (Sandbox Code Playgroud)
当我输入一些文本时,如果在数据库中找不到它并且没有通过ajax加载,我无论如何都可以选择它,原因属性tags设置为true. 然后我有以下代码
$('#order_address_select').change(function () {
alert($("#order_address_select option[data-select2-tag='true']").val());
});
Run Code Online (Sandbox Code Playgroud)
问题是当我输入文本并将其选择为标签时,事件不会第一次触发。但是,当我再次输入文本并选择它时,代码会提醒先前选择的选项的值。例如:我输入“aaa”,选择它,没有任何反应,然后我输入“bbb”,选择它,并收到“aaa”警报
我正在使用 angular 和 firestore。我正在检查 firestore 中我的路线守卫的价值。
我发现在页面刷新时,它返回为未定义。但是,如果我只是硬编码 true 或 false 的返回,它就可以工作。
我的 if 语句中的任何日志总是正确返回,但由于某种原因似乎没有更新我的全局变量。
如果我使用我的网站导航返回根目录并浏览我的网站,它可以正常工作。但是,当我刷新页面时,它返回为未定义。
这可能是一个范围界定问题吗?
路线守卫
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot, CanActivate, Router } from '@angular/router';
import { AuthService } from './auth.service';
import { AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument } from 'angularfire2/firestore';
import { Subscription } from 'rxjs/Subscription';
//testing
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
@Injectable()
export class CheckBillingService implements CanActivate {
private _subscription: Subscription;
private userBillingDocRef: AngularFirestoreDocument<any>;
userBilling: Observable<any>; …Run Code Online (Sandbox Code Playgroud) javascript scoping typescript angular google-cloud-firestore
我试图取消订阅ngOnDestroy中的一个observable,但它告诉我它在Observable类型中不存在.
export class AppComponent implements OnInit {
public caseData;
constructor(private _caseService: CaseService,
private _title: Title,
private _metaService: Meta) { }
ngOnInit(): void {
this._caseService.GetCaseData('en', 'English');
this._caseService.caseData$.subscribe(res => { this.caseData = res },
(error) => { console.log(error) });
}
ngOnDestroy() {
this._caseService.caseData$.unsubscribe(); //says it does not exist
}
}
Run Code Online (Sandbox Code Playgroud) 我从 JSON 数组创建了一个 observable,我想为数组内的每个元素添加新值,我需要根据元素的索引来做。
到目前为止,我只能为所有元素添加相同的键值。有没有办法将索引引入地图功能?例如,我可以说第一个元素“is_leader”为真,而对于所有其他元素,它为假。
到目前为止的代码:
this.dataSubscription = this.dataService.getTestData().subscribe(
res => {
this.allData = res.map(data => {
data['is_leader'] = true; // Here I would like a condition
return data;
});
}
);
Run Code Online (Sandbox Code Playgroud)
在 Angular 2 中工作。
看看这个非常基本的打字稿角度文件。这是一个非常基本的组件
import { Component } from '@angular/core';
import { Observable } from "rxjs/Observable";
@Component({
selector: 'tagcomposant1',
templateUrl: './composant1.component.html'
})
export class Composant1Component {
ngOnInit() {
console.log("ngOnInit");
alert('ngOnInit');
}
btn_click() {
console.log("btn_click");
alert("btn_click");
}
}
Run Code Online (Sandbox Code Playgroud)
这是 html 文件:
<button (click)="btn_click()">test</button>
Run Code Online (Sandbox Code Playgroud)
我不明白 和ngOnInit()是btn_click()在服务器端还是在浏览器中运行。我可以在服务器控制台中看到一些日志消息。以及浏览器中的一些警报。所以我不明白。
我正在开发一个 ASP.NET Core 2 MVC 角度项目
谢谢