我创建了一个子组件,它有一个我想要调用的方法.
当我调用这个方法时它只会触发该console.log()行,它不会设置test属性??
以下是我的更改快速启动Angular应用程序.
亲
import { Component } from '@angular/core';
import { NotifyComponent } from './notify.component';
@Component({
selector: 'my-app',
template:
`
<button (click)="submit()">Call Child Component Method</button>
`
})
export class AppComponent {
private notify: NotifyComponent;
constructor() {
this.notify = new NotifyComponent();
}
submit(): void {
// execute child component method
notify.callMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
儿童
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'notify',
template: '<h3>Notify {{test}}</h3>'
})
export class NotifyComponent implements OnInit {
test:string;
constructor() …Run Code Online (Sandbox Code Playgroud) 假设我有以下对象数组,请将其命名为itemArray;
{
"totalItems": 2,
"items": [
{
"id": 1,
"name": "foo"
},
{
"id": 2,
"name": "bar"
},
]
}
Run Code Online (Sandbox Code Playgroud)
我有一个订阅,返回只有id 2的更新结果.如何在不循环整个数组的情况下更新对象数组?
我想要的是类似下面的例子;
updateUser(user){
this.myservice.getUpdate(user.id)
.subscribe(newitem => {
this.updateArray(newitem);
});
}
updateArray(newitem){
this.itemArray.items[newitem.id].name = newitem.name
}
Run Code Online (Sandbox Code Playgroud)
甚至更好,更换整个物体;
updateArray(newitem){
this.itemArray.items[newitem.id] = newitem
}
Run Code Online (Sandbox Code Playgroud)
但是,此示例根据数组的索引更新数组.那么我如何根据newitem.id进行更新呢?
评论中要求的模板:
<tr *ngFor="let u of itemsArray.items; let i = index">
<td>{{ u.id }}</td>
<td>{{ u.name }}</td>
<td>
<input type="checkbox" checked="u.accepted" [(ngModel)]="itemsArray.items[i].accepted" (ngModelChange)="updateUser(u)">
<label for="singleCheckbox-{{i}}"></label>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud) 我不知道如何对这样的方法进行API调用:
[HttpGet]
[ActionName("GetSupport")]
public HttpResponseMessage GetSupport(int projectid)
Run Code Online (Sandbox Code Playgroud)
因为它是GET但仍然有一个参数要通过,怎么做?它会是这样的吗?
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('projectid', this.id);
this.http.get('http://localhost:63203/api/CallCenter/GetSupport', { headers: headers })
Run Code Online (Sandbox Code Playgroud) tl; dr:基本上我想将Angular ngOnDestroy与Rxjs takeUntil()运算符结合起来. - 那可能吗?
我有一个Angular组件,可以打开几个Rxjs订阅.当组件被销毁时,需要关闭它们.
一个简单的解决方案是:
class myComponent {
private subscriptionA;
private subscriptionB;
private subscriptionC;
constructor(
private serviceA: ServiceA,
private serviceB: ServiceB,
private serviceC: ServiceC) {}
ngOnInit() {
this.subscriptionA = this.serviceA.subscribe(...);
this.subscriptionB = this.serviceB.subscribe(...);
this.subscriptionC = this.serviceC.subscribe(...);
}
ngOnDestroy() {
this.subscriptionA.unsubscribe();
this.subscriptionB.unsubscribe();
this.subscriptionC.unsubscribe();
}
}
Run Code Online (Sandbox Code Playgroud)
这有效,但有点多余.我特别不喜欢那样 - 这unsubscribe()是其他地方,所以你必须记住这些是相互关联的. - 组件状态受订阅污染.
我更喜欢使用takeUntil()运算符或类似的东西,使它看起来像这样:
class myComponent {
constructor(
private serviceA: ServiceA,
private serviceB: ServiceB,
private serviceC: ServiceC) {}
ngOnInit() {
const destroy = Observable.fromEvent(???).first();
this.subscriptionA …Run Code Online (Sandbox Code Playgroud) 我已经使用了ASP.NET Identity一段时间了,并且一直在关注JWT(JSON Web Token),因为它们看起来非常有趣且易于使用.
JWT.IO有一个调试令牌的好例子/工具.
但是,我不完全确定JWT在后端的工作方式,你还会使用Identity吗?
另外,令牌(Bearer vs JWT)如何比较?哪个更安全?
我在Angular上观看了一些课程,发现有不同的方法来管理来自Http请求的数据.
.map(),.subscribe().toPromise(),.then(),.catch()我toPromise()在我的应用程序中使用过,因为我发现它类似于AngularJS Http服务.
在什么情况下我需要使用Observables?
我很难将我的大脑缠绕在Angular的观察者身上.我来自PHP的世界,事情肯定不是异步的.
我有一个组件,只显示一般主题的消息列表.现在,我有一个所有消息都属于的主题.如果主题不存在,则应创建该主题.消息和主题调用都是通过REST API完成的.
在非同步世界中,我会按顺序编程.消息服务将查看主题是否存在.如果没有,那么它有主题服务创建它.在有主题后,它会获取该主题中的所有消息.
我知道你订阅了一个observable,但是当需要按顺序发生一系列事情时会发生什么?的角2的HTTP文档经过当一个呼叫由更新英雄列表的一个非常简单的例子.
零件
export class NotificationListComponent implements OnInit {
constructor(private _notificationService:NotificationService) {
}
***
ngOnInit() {
this.getNotifications();
}
getNotifications() {
this._notificationService.getNotifications()
.subscribe(
notifications => this.notifications = notifications,
error => this.errorMessage = <any>error);
}
Run Code Online (Sandbox Code Playgroud)
通知服务
...
getNotifications() {
// call the topic service here for general topic??
return this.http.get('/messages?order[datesent]=DESC')
.map((res) => {
return res.json()["hydra:member"];
})
.map((notifications:Array<any>) => {
let result:Array<Notification> = [];
notifications.forEach((jsonNotification) => {
var Notification:Notification = {
message: jsonNotification.message,
topic: jsonNotification.topic,
datesent: new Date(jsonNotification.datesent), …Run Code Online (Sandbox Code Playgroud) 我ls -al /system/framework/在我的Android 5.0.1手机上做过adb shell
我注意到大约95%的.jar文件有309个字节.在使用adb pull和解压缩它们之后拉出一个这样的文件显示.jar只包含文件/META-INF/MANIFEST.MF
dex这些jar文件的实际代码在哪里.?
PS我的手机没有扎根.
我正在学习/研究Angular项目,我已经做了很多,我尝试以"正确的方式"做事,所以现在我想做的是:
我想从子组件到父组件获取变量(输出),但我不想使用输出,我不想听它,我想在父母需要的时候得到它,像child.getVariable()我这样的东西我发现一个帖子说我应该使用childview,但问题与我的不一样,所以我想知道使用childview从子组件获取数据是一个好习惯吗?
当我将这行代码添加到我的@Component:
directives: [HeroDetailComponent]
Run Code Online (Sandbox Code Playgroud)
代码中断,并给我这个错误:
GET http://localhost:3000/@angular/core 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)
这些是我的脚本index.html:
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
Run Code Online (Sandbox Code Playgroud)
如果我错过了诊断此问题的任何信息,请告诉我,我会将其包含在此处.
angular ×8
typescript ×4
adb ×1
android ×1
angularjs ×1
childviews ×1
components ×1
jwt ×1
observable ×1
output ×1
rxjs ×1
rxjs5 ×1