我对属性指令有疑问。我已经按照教程进行操作了。
指令是使用 CLI 生成的,因此我使用了ng g directive <directivename>,并且特意与 一起放在顶层app.module.ts。
我的app.module.ts看起来像这样(由于模块的专有名称,我必须省略所有导入):
// Directives
import { EventhoverDirective } from './eventhover.directive';
@NgModule({
declarations: [
// all the relevant component inputs are here
EventhoverDirective
],
imports: [
// modules are here
],
providers: [
// providers are here
],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
指令本身看起来像:
import { Directive, HostListener, OnInit, Renderer2, ElementRef } from '@angular/core';
@Directive({
selector: '[appEventhover]'
})
export class EventhoverDirective implements OnInit …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Angular 5 调用 Web 服务到 PHP。
我正在使用 POST 方法,但在 PHP 端检索数据时遇到问题。
发送数据显示在有效负载中,但不会在 php 端检索。
角度服务.ts
this.URL = "http://localhost/angular/WEBSERVICE_PHP/test.php";
const headers = new Headers();
headers.append('Content-Type', 'application/json');
let data = 'visitor_id=55';
return this.http
.post(this.URL,JSON.stringify(data),{
headers: headers
})
.map( Response => console.log(Response) );
Run Code Online (Sandbox Code Playgroud)
PHP页面
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: POST, GET");
header('P3P: CP="CAO PSA OUR"'); // Makes IE to support cookies
header('content-type: text/plain');
header("content-type: application/x-www-form-urlencoded");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-
Requested-With");
header("Access-Control-Max-Age: 172800");
if(isset($_POST))
{
// $post = 'test data'; // This data …Run Code Online (Sandbox Code Playgroud) 我正在学习 Angular 5+,最近谈到主题/订阅部分,我看到很多教程都想以某种方式使用订阅:
但是,我不确定我们是否必须订阅/取消订阅 ngOnInit 和 ngOnDestroy 中组件中的每个订阅。例如,如果我的订阅将通过按钮单击事件进行更新,我应该在组件中订阅哪个计划?
为什么我们总是在 ngOnInit 中订阅订阅?ngOnInit 就像页面生命周期中的 Page_Load 一样,因此它只会在第一次被调用一次,如果是这样,每当订阅更新时,ngOnInit 是否会一遍又一遍地被触发?如果是这样,我的组件是否会被一遍又一遍地加载,这在大型应用程序中会导致性能问题?
我刚刚将 matRipple 属性添加到我的 div 中,如下所示:
<div matRipple class='icon-wrapper'>
...
</div>
Run Code Online (Sandbox Code Playgroud)
红色边框是 div 元素的实际大小。正如您所看到的,波纹动画逃脱了 div 元素的边界。如何隐藏溢出的波纹动画?overflow: hidden没有影响。
如何将以下字符串数组转换为类型数组(或函数?或者这些验证器是什么......)?
let valStrings: string[] = ["Validators.required", "Validators.maxLength(10)"];
Run Code Online (Sandbox Code Playgroud)
并将其转换为:
let validators: ValidatorFn[] = [ Validators.required, Validators.maxLength(10) ];
Run Code Online (Sandbox Code Playgroud)
我有一个返回验证规则的网络服务。这是尝试集中所有验证规则,以保持服务器和客户端验证同步,因此字符串来自HttpClient具有 JSON 结果的调用。当然,我们仍然将实际的实现分开,但至少两者定义的规则应该相同。
该验证器数组将被传递到 a 中,FormControl以利用 Angular 中的反应式表单进行客户端验证。
eval()这是应该使用的地方吗?
谢谢你-亚当
我正在使用 ngx-data 表并使用 ngx-data 表的复选框类型。我只想选择当前页面行,但当我选择所有选项时,它会选择数组中的所有行。我的代码在这里
<ngx-datatable-column [width]="50" [sortable]="false" [canAutoResize]="false" [draggable]="false" [resizeable]="false">
<ng-template class="datatable-checkbox" ngx-datatable-header-template let-value="value" let-allRowsSelected="allRowsSelected"
let-selectFn="selectFn">
<div class="checkbox-fade fade-in-default datatable-header-cell-label">
<label>
<input type="checkbox" [checked]="allRowsSelected" (change)="selectFn(!allRowsSelected)" />
<span class="cr">
<i class="cr-icon icofont icofont-ui-check txt-primary"></i>
</span>
</label>
</div>
</ng-template>
<ng-template class="datatable-checkbox" ngx-datatable-cell-template let-value="value" let-isSelected="isSelected" let-onCheckboxChangeFn="onCheckboxChangeFn">
<div class="checkbox-fade fade-in-default datatable-header-cell-label">
<label>
<input type="checkbox" [checked]="isSelected" (change)="onCheckboxChangeFn($event)" />
<span class="cr">
<i class="cr-icon icofont icofont-ui-check txt-primary"></i>
</span>
</label>
</div>
</ng-template>
</ngx-datatable-column>
Run Code Online (Sandbox Code Playgroud)
如何仅在全选选项上选择当前页行?
我遇到以下问题,我需要使用 forEach 循环迭代 Angular 中表单的控件属性。我正在编写以下代码:
const arr = this.bankForm.controls;
arr.forEach((element: {[key: string]: AbstractControl}) => {
});
Run Code Online (Sandbox Code Playgroud)
我有下一个错误:
我正在尝试想出类似 Facebook 上的标记功能的东西,即每当按下“@”键时,我的自动完成功能就会被触发,并且我应该能够看到与输入帖子“@”的数据相对应的选项。
我无法绑定 keydown(或任何按键事件)上的自动完成功能
任何有关如何实现此功能的建议将不胜感激,我的最后手段是提出我自己的自动完成模块
尝试获取元素引用名称但不起作用。如果有人知道请帮助找到解决方案。
Alert 应该像容器一样。因为那是元素引用。
应用程序组件.html:
<div (click)="test(event)" #container></div>
Run Code Online (Sandbox Code Playgroud)
应用程序组件.ts:
test(e){
alert(e.elementRef);
//Output should be like alert("container");
}
Run Code Online (Sandbox Code Playgroud) 我在使用Angular 5服务时面临以下问题,请您帮我解决下面的代码有什么问题
我已经解决了以下问题,但没有帮助我
我只想初始化类中的值并在方法中使用它
虽然我已经在类中定义的URL值我得到误差Cannot read property 'url' of undefined为线console.log(this.url);
@Injectable()
export class OwnService {
public accessTokenvalue = '';
public url = 'https://www.someurl.com/id=';
constructor(private hp: HelpService) {
}
public gethpPhotos() {
this.hp.login()
.then(function (response: LoginResponse) {
console.log(response);
console.log(this.url);
})
.catch((error: any) => console.error(error));
}
}
Run Code Online (Sandbox Code Playgroud) angular5 ×10
angular ×8
typescript ×4
angular6 ×1
angular7 ×1
angular8 ×1
attributes ×1
css ×1
directive ×1
html ×1
javascript ×1
ngoninit ×1
php ×1
rest ×1
subject ×1
subscription ×1
web-services ×1