我有一个弹出的更改个人资料图片模式,所以你上传图片按保存,应该发生的是个人资料图片在整个网站上更新,但没有发生,只有在你刷新个人资料图片后才会更新
个人资料图片更改模式的我的保存功能
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/
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数
我是Rails的新手,所以请原谅简单的问题。我正在为一家公司创建一个网站。那家公司想在网站上展示它的客户。我想让客户自己管理这个。我正在为“客户”生成一个表格,我想要的三列是:公司名称、公司描述和Logo。对于名称,我使用的是name:string但不确定如何在脚本/生成脚手架终端命令中最好地创建描述列(因为我打算将其设置为文本区域)和图片。我怀疑描述(我想成为一个文本区域)应该仍然是描述:字符串,然后以实际形式进行调整。不确定如何处理图片字段。那么……说来话长:我在脚手架命令中输入什么来生成描述和图片列? 最佳答案 对于“文本”数
我正在尝试为我的iOS应用程序设置cocoapods但是当我执行命令时:sudogemupdate--system我收到错误消息:当前已安装最新版本。中止。当我进入cocoapods的下一步时:sudogeminstallcocoapods我在MacOS10.8.5上遇到错误:ERROR:Errorinstallingcocoapods:cocoapods-trunkrequiresRubyversion>=2.0.0.我在MacOS10.9.4上尝试了同样的操作,但出现错误:ERROR:Couldnotfindavalidgem'cocoapods'(>=0),hereiswhy:U
这太简单了,太荒谬了,我在任何地方都找不到关于它的任何信息,包括API文档和Rails源代码:我有一个:belongs_to关联,我开始理解当您没有关联时您在Controller中调用的正常模型方法与您有关联时调用的方法略有不同。例如,我的关联在创建Controller操作时运行良好:@user=current_user@building=Building.new(params[:building])respond_todo|format|if@user.buildings.create(params[:building])#etcetera但我找不到关于更新如何工作的文档:@user
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
升级到OSXYosemite后,我现有的pow.cx安装不起作用。升级到最新的pow.cx无效。通过事件监视器重新启动它也没有成功。 最佳答案 卸载(!)并重新安装解决了这个问题。curlget.pow.cx/uninstall.sh|shcurlget.pow.cx|sh 关于ruby-on-rails-OSXYosemite更新破坏了pow.cx,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/q
我们在Ubuntu14.04和Gitlab9.3.7上运行,运行良好。我们正在尝试更新到Gitlabv9.3.8的最新安全补丁,但它给我们这个错误:Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension.currentdirectory:/home/git/gitlab/vendor/bundle/ruby/2.3.0/gems/re2-1.0.0/ext/re2/usr/local/bin/ruby-r./siteconf20170720-19622-15i0edf.rbextconf.rbcheckingformain(
我遇到了以下问题。我有一个名为user的模型,它有一个名为activated的列。我试图通过激活的方法更新该值?但它给我错误:验证失败:密码不能为空,密码太短(最少6个字符)这对我来说没有意义,因为我没有接触密码字段!我只想更新激活的列。我把我认为相关的代码放在这里,但如果你认为你需要更多,请问:)非常感谢您!型号:attr_accessor:passwordattr_accessible:name,:email,:password,:password_confirmation,:activatedhas_many:sucu_votesemail_regex=/\A[\w+\-.]+@
我正在尝试找出一种方法来显示来自不在RAILS_ROOT下(在RedHat或Ubuntu环境中)的已安装文件系统的图像。我不想使用符号链接(symboliclink),因为这个应用程序实际上是通过Tomcat部署的,而当我关闭Tomcat时,Tomcat会尝试跟随符号链接(symboliclink)并删除挂载中的所有图像。由于这些文件的数量和大小,将图像放在public/images下也不是一种选择。我查看了send_file,但它只会显示一张图片。我需要在一个格式良好的页面中显示6个请求的图像。由于膨胀,我宁愿不使用Base64编码,但我不知道如何将图像数据与呈现的页面一起传递下去。