- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一个弹出的更改个人资料图片模式,所以你上传图片按保存,应该发生的是个人资料图片在整个网站上更新,但没有发生,只有在你刷新个人资料图片后才会更新
个人资料图片更改模式的我的保存功能
save(): void {
const self = this;
this.saving = true;
self._profileService.updateProfilePicture(input)
.finally(() => { this.saving = false; })
.subscribe(() => {
const self = this;
self._$jcropApi.destroy();
self._$jcropApi = null;
abp.event.trigger('profilePictureChanged');
console.log('changed');
this._userService.updateProfilePicture();
self.close();
});
}
因此,当用户按下保存时,它会上传图像,然后调用我的用户服务上的 updateProfilePicture 函数...
我的用户服务是这样设置的..
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Subject } from 'rxjs/subject';
@Injectable()
export class UserService {
private profilePictureSource = new Subject<any>();
profilePicture = this.profilePictureSource.asObservable();
updateProfilePicture() {
this.profilePictureSource.next();
}
}
然后在组件中我要更改个人资料图片
import { UserService } from '/userService';
import { ProfileService } from '/profileService';
export class ....
profilePicture: any;
constructor(
private _userService: UserService,
private _profileService: ProfileService
) { }
ngOnInit() {
// grab the profile picture on init
this.userPic();
// Listen for profile picture change
this._userService.profilePicture.subscribe(result => {
this.userPic();
}
}
userPic() {
this._profileService.getProfilePicture().subscribe(result => {
if (result && result.profilePicture) {
this.profilePicture = 'data:image/jpeg;base64,' + result.profilePicture;
}
});
}
然后在我的 HTML 中
<img [src]="profilePicture" />
我试图注释掉 self.close();
只是因为它导致了一个问题,比如它在调用服务之前就关闭了,但这并没有改变任何东西
编辑
当我使用 chrome 调试器时,我在所有函数和服务调用上都设置了断点。当我按下保存时,userService 函数触发了一个断点。但之后堆栈中没有其他函数被调用,我不确定为什么?
第二次编辑我按照 Abylay Kurakbayev 的回答进行了更改
profilePicture = this.profilePictureSource.asObservable(); //from
profilePicture = this.profilePictureSource; //to
但这并没有解决问题
编辑 3
这里是 getProfilePicture() 函数
getProfilePicture(): Observable<GetProfilePictureOutput> {
let url_ = this.baseUrl + "/api/services/app/Profile/GetProfilePicture";
url_ = url_.replace(/[?&]$/, "");
let options_ : any = {
method: "get",
headers: new Headers({
"Content-Type": "application/json",
"Accept": "application/json"
})
};
return this.http.request(url_, options_).flatMap((response_ : any) => {
return this.processGetProfilePicture(response_);
}).catch((response_: any) => {
if (response_ instanceof Response) {
try {
return this.processGetProfilePicture(response_);
} catch (e) {
return <Observable<GetProfilePictureOutput>><any>Observable.throw(e);
}
} else
return <Observable<GetProfilePictureOutput>><any>Observable.throw(response_);
});
}
编辑 4这是 processGetProfilePicture() 方法
protected processGetProfilePicture(response: Response): Observable<GetProfilePictureOutput> {
const status = response.status;
let _headers: any = response.headers ? response.headers.toJSON() : {};
if (status === 200) {
const _responseText = response.text();
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 ? GetProfilePictureOutput.fromJS(resultData200) : new GetProfilePictureOutput();
return Observable.of(result200);
} else if (status !== 200 && status !== 204) {
const _responseText = response.text();
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return Observable.of<GetProfilePictureOutput>(<any>null);
}
编辑 5
我想知道是否有办法强制刷新 userPic()
函数所在的组件?因为刷新页面后个人资料图片会立即更新??
谢谢
最佳答案
据我所知,UserService
是如何在提供者中声明的?
In order to check this
UserService 构造函数中的一个 console.log() 以查看该构造函数是否被多次调用
还要检查您应该只有一个提供程序的组件中的提供程序。
You must have the same istance in order for this flow to work as you are describing it. If you have one instance across all components can you make a plunker or provide some access to the full implementation of the components.
关于javascript - 个人资料图片未跨组件更新 Angular 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50167344/
在我的应用程序中播放背景音乐时遇到问题。 首先,我在第一个 Storyboard View Controller 中的 ViewDidLoad 方法中开始播放音乐。即使我从一个页面跳转到另一个页面,它
我想跨行连接数组,然后进行不同的计数。理想情况下,这会起作用: WITH test AS ( SELECT DATE('2018-01-01') as date, 2 as value,
这是一个场景: Repo A 是一个包含大量模块和依赖项的怪异代码。安装起来并不容易。它由其他人维护并托管在 Github 上。 Repo A 包含一个非常有用的模块 X,并且几乎不依赖于 Repo
目前,我在一台服务器上运行了一个应用程序。有一个 crontab 设置,因此根据指定的规则,在某些时间运行任务。 现在,我正在考虑将我的应用程序迁移到 docker 容器中,以便我能够独立运行我的应用
我有一个全局表,我想在两个不同的 Lua 状态之间保持同步。根据我所阅读和理解的内容,唯一的方法似乎是,在我的 C 后端,在状态之间进行表的深层复制(如果表已被修改)。有没有更好的办法 ? 另外,我看
我们目前有一个 asmx webservice,它公开了一个方法来对 Sql 数据库进行各种更新,内部包装在 SqlTransaction 中。 我正在 WCF 中重写此服务,我们希望将现有方法拆分为
我是 Qt 的新手,所以请原谅这个问题的简单性,但我对 Qt 线程有点困惑。假设我有 3 个线程:主要的默认 GUI 线程和我自己创建的 2 个线程(称为 WorkerThread)。我的每个 Wor
我们的产品有一个 Restful API 和一个服务器渲染的应用程序(CMS)。两者共享数据库。两者都是用django编写的 两者所需的字段和模型并不是相互排斥的,有些仅针对 API,有些针对 CMS
我正在实现一个基于角色的访问控制系统,它具有以下数据库表。 groups --------- id (PK) name level resources --------- id (PK) name r
我有三个应用程序,为了便于管理,我希望将它们分开。他们按照建议作为 Plack 服务器运行 here , 代理在 nginx 后面。 我想有一个单独的应用程序来管理登录,并在所有其他应用程序之间共享该
我的主窗口上有一个 UIWebView。我可以通过我的第二个 View Controller 来控制它吗?如果可以的话你能给我举个例子吗? 最佳答案 是的,你可以。 “如何”是一个基本的 Cocoa/
我想制作一个小型应用程序,从连接到串行端口的设备收集数据,并将其通过 LAN 传递到另一个应用程序,后者将其存储在数据库中。 我已经在一台 PC 上的一个应用程序中完成了此操作,因此实际上会将应用程序
从主 AppDomain,我试图调用在不同 AppDomain 中实例化的类型中定义的异步方法。 比如下面的类型MyClass继承自 MarshalByRefObject并在新的 AppDomain
因为 LiveServerTestCase继承自 TransactionTestCase ,默认行为是在每个测试方法结束时删除测试数据。我想用LiveServerTestCase类,但保留方法之间的测
我正在开发我的第一个 WPF/MVVM 应用程序,但我在命令知识方面遇到了限制! 这是我的场景。 我有一个窗口——Customer.xaml。 它包含 2 个用户控件 查看CustomerSearch
这是我的 WPF 应用程序模型的简化版本: Employee +Name:string Client +Name:string +PhoneNumber:string Appointmen
我有一个 mercurial 存储库,它使用子存储库功能(如 .hgsub 文件中定义的)引入依赖项,但我正在努力让它在 TeamCity 中工作。 我启用了 mercurial_keyring 扩展
我正在尝试使用新的 Azure 虚拟网络公共(public)预览版的对等互连功能来加入我在两个不同订阅(即不同租户)上拥有的两个网络。这可能吗?我没有看到任何其他说法,但是当我尝试在 PowerShe
我有 2 个存储库。由于主干代码位于一个 protected 存储库中,因此我进行了 checkout ,然后 checkin 到另一个存储库(因为用户没有第一个 protected 存储库的权限)。
我有一个项目,其调用结构与此类似: 主要项目/应用 我的图书馆代码 别人的库代码 我的图书馆代码 一切都是用 C# 编写的,我可以访问“其他人的库代码”。他们的代码不包含在我的项目中,因为它是开源的而
我是一名优秀的程序员,十分优秀!