我想基于窗口重新调整大小事件(加载和动态)执行一些任务.
目前我有我的DOM如下:
<div id="Harbour">
<div id="Port" (window:resize)="onResize($event)" >
<router-outlet></router-outlet>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
事件正确触发
export class AppComponent {
onResize(event) {
console.log(event);
}
}
Run Code Online (Sandbox Code Playgroud)
如何从此事件对象中检索宽度和高度?
谢谢.
我的数据库中有一个名为"dob"的列,类型为datetime.如何在SQL Server 2005中的特定DoB之后选择所有行?
采用以下模板示例.我用as语法创建用户的模板上下文,并希望将该上下文传递给userTmpl.据我所知,没有办法将上下文传递给ngIf条件使用的内容.在此示例中,是showUser属性.
<ng-container *ngIf="user$ | async as user">
<ng-container *ngIf="showUser; then userTmpl; else emptyTmpl"></ngcontainer>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
如何将user模板输入变量传递给嵌套的templateRef?
查看源代码,该ngIf指令看起来像是将上下文设置为条件ngIf.我不知道基本上覆盖模板中使用的上下文变量的方法
这样的事情是理想的,但没有办法做到这一点.
<ng-container *ngIf="showUser; then userTmpl; else emptyTmpl; context: user"></ngcontainer>
Run Code Online (Sandbox Code Playgroud) 在搜索并没有提出解决方案后,我发布此代码片段以获得一些帮助.
$scope.createAddress = function () {
$http({
method: 'POST',
url: '/addressBook/api/Person',
data: $scope.person,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).success(function (data) {
$location.path('/addressBook');
});
}
Run Code Online (Sandbox Code Playgroud)
成功发布后,我想重定向到另一个页面.$ location.path没有实现这一点.我尝试了$ scope.apply(),因为其他一些人已经取得了成功.我错过了什么或不了解$ location用于什么?代码被击中了.
包含@ViewChildren的父组件不会返回动态创建的组件的结果.
容器组件包含一个highlight指令,动态生成的组件highlight在其模板中包含一个指令.查询时@ViewChildren查询长度返回1.预期结果是2.
从HTML中可以看出,DOM上肯定有两个高亮指令.
<container-component>
<div></div>
<dynamic-component ng-version="4.0.0">
<div highlight="" style="background-color: yellow;">Dynamic!</div>
</dynamic-component>
<div highlight="" style="background-color: yellow;">Number of Highlights
<div></div>
</div>
</container-component>
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
https://plnkr.co/edit/LilvHJgFjPHnPuaNIKir?p=preview
容器组件
@Component({
selector: 'container-component',
template: `
<div #contentProjection></div>
<div highlight>Number of Highlights {{highlightCount}}<div>
`,
})
export class ContainerComponent implements OnInit, AfterViewInit {
@ViewChildren(HighlightDirective) private highlights: QueryList<HighlightDirective>;
@ViewChild('contentProjection', { read: ViewContainerRef }) private contentProjection: ViewContainerRef;
constructor(
private resolver: ComponentFactoryResolver
) {
}
ngOnInit() {
this.createDynamicComponent();
}
ngAfterViewInit() { …Run Code Online (Sandbox Code Playgroud) 我正在构建一个简单的反应形式。为了简单起见,假设我要显示的唯一数据是日期。
test.component.html
<form novalidate [formGroup]="myForm">
<input type="date" formControlName="date">
</form>
Run Code Online (Sandbox Code Playgroud)
test.component.ts
private date: Date = Date.now();
ngOnInit() {
this.myForm = this.fb.group({
date: [this.date, [Validators.required]]
});
}
Run Code Online (Sandbox Code Playgroud)
模板上的输入type = date字段要求日期格式为'yyyy-MM-dd'。事件中的值是一个JavaScript Date对象。
如何在模板级别修改数据,以便输入值正确?
我尝试过的
一种方法是将DatePipe注入到我的组件中,并在代码中应用转换。
date: [datePipe.transform(this.event.date, 'yyyy-MM-dd'), [Validators.required]]
Run Code Online (Sandbox Code Playgroud)
但这将模板的实现细节与组件联系在一起。例如,如果NativeScript模板要求日期采用格式,该MM/dd/yyyy怎么办?formGroup不再有效。
我有一个JavaScript代码,非常适合拖动对象...但是当我将主体缩放到0.5时...
transform:scale(0.5);
鼠标和拖动的对象的位置不同。我怎样才能解决这个问题?还是有可能吗?...谢谢。
这是一个小提琴:http : //jsfiddle.net/Xcb8d/65/
在使用 Redux 和 Angular 时寻求一些建议。过去几天我一直在研究 Redux,并且确实认为它是存储应用程序数据的好方法。我遇到问题的部分是是否保留商店内的所有内容或仅保留某些部分。理想情况下,我认为整个应用程序应该通过商店运行,但对于表单来说,这似乎非常乏味。
例如,假设我正在使用表单来添加新产品。以下是我的一些痛点。
我想将用户减速器(存储)与实际的表单状态分开。我应该为每个组件创建一个单独的表单减速器吗?
必须将每个输入字段保存回商店听起来工作量很大。我已经看到库redux-form简化了这一点,但它是针对 React 的。
在使用 Redux 在 Angular 中创建表单时,有人有什么好的建议吗?
我担心,通过省略,包含数据库密码或会话密钥等秘密的模块可以包含在WebPack或Browserify捆绑包中.
即使我不直接导入这些模块,我也可能不小心从客户端入口点模块间接导入它们.
有没有办法将这些文件列入黑名单,以便这些捆绑包拒绝捆绑它们?尽可能愿意遵循可避免此类问题的最佳实践,但拥有这样一个安全网会很好.
我很难理解为什么combineLatest不返回最新值。这个例子有些人为,但至少说明了我的问题。请注意,当观察值正确时,color来自combineLatestobservable 的值将返回先前的值subject.value。就像color$没有发出可观察到的。
import { map, distinctUntilChanged, combineLatest } from 'rxjs/operators'
import { Observable } from 'rxjs/observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
const main$ = new BehaviorSubject({color: 'red'});
const color$ = main$.pipe(
map(state => state.color),
)
main$.pipe(
combineLatest(color$)
)
.subscribe(([state, color]) => {
console.log(state, color, main$.value.color);
})
main$.next({
color: 'yellow'
});
Run Code Online (Sandbox Code Playgroud)
实际产量
{color: "red"} "red" "red"
{color: "yellow"} "red" "yellow"
{color: "yellow"} "yellow" "yellow"
Run Code Online (Sandbox Code Playgroud)
预期产量
{color: "red"} "red" "red"
{color: …Run Code Online (Sandbox Code Playgroud) angular ×5
angularjs ×2
javascript ×2
angular-pipe ×1
css3 ×1
date ×1
forms ×1
html ×1
location ×1
post ×1
redirect ×1
redux ×1
rxjs ×1
rxjs5 ×1
secret-key ×1
sql ×1
sql-server ×1
transform ×1
webpack ×1