angular - 将拍摄的照片移动到另一个组件
问题描述
我创建了一个应用程序,点击按钮后,相机启动。如果我拍照,我希望它出现在一个新窗口中,并减少了其他进程的按钮。我提供服务,几乎一切都还好,但如果我拍照,我不会被重新路由到第二个组件,我应该在那里看到带有我的自定义按钮的图片。我知道,我有一个错误,但我不知道在哪里。
第一个组件:
import { takePicture, requestPermissions } from "nativescript-camera";
import { ImageAsset } from "tns-core-modules/image-asset";
import { ZdjecieService } from "../zdjecie.service";
declare var android: any;
@Component({
selector: "ns-glowna",
templateUrl: "./glowna.component.html",
styleUrls: ["./glowna.component.css"]
})
export class GlownaComponent implements OnInit {
public saveToGallery: boolean = false;
public allowsEditing: boolean = false;
public keepAspectRatio: boolean = true;
public width: number = 320;
public height: number = 240;
public cameraImage: ImageAsset;
public actualWidth: number;
public actualHeight: number;
public scale: number = 1;
public labelText: string;
constructor(private service: ZdjecieService) {}
ngOnInit() {}
onTakePictureTap(args) {
requestPermissions().then(
() => {
takePicture({
width: this.width,
height: this.height,
keepAspectRatio: this.keepAspectRatio,
saveToGallery: this.saveToGallery,
allowsEditing: this.allowsEditing
}).then(
(imageAsset: any) => {
this.cameraImage = imageAsset;
let that = this;
imageAsset.getImageAsync(function(nativeImage, ex) {
if (ex instanceof Error) {
throw ex;
} else if (typeof ex === "string") {
throw new Error(ex);
}
});
},
error => {
console.log("Error: " + error);
}
);
},
() => alert("permissions rejected")
);
}
}
第二部分:
import { GlownaComponent } from "../glowna/glowna.component";
import { ZdjecieService } from "../zdjecie.service";
@Component({
selector: "ns-check-photo",
templateUrl: "./check-photo.component.html",
styleUrls: ["./check-photo.component.css"]
})
export class CheckPhotoComponent implements OnInit {
cameraImage: any;
constructor(private photoService: ZdjecieService) {}
ngOnInit() {
this.cameraImage = this.photoService.camImage;
this.getImage();
}
getImage(): void {
this.photoService
.getPhoto()
.subscribe(cameraImage => (this.cameraImage = cameraImage));
}
}
HTML第二个组件
<ScrollView>
<Image [src]="cameraImage" stretch="aspectFit" margin="10"></Image>
<Button text="next"></Button> </ScrollView
></StackLayout>
服务:
import { GlownaComponent } from ".//glowna/glowna.component";
import { Observable, of } from "rxjs";
@Injectable({
providedIn: "root"
})
export class ZdjecieService {
camImage: any;
getPhoto(): Observable<any> {
this.camImage = GlownaComponent;
return this.camImage;
}
constructor() {}
}
路由:
import { NgModule } from "@angular/core";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { Routes } from "@angular/router";
import { GlownaComponent } from "./glowna/glowna.component";
import { CheckPhotoComponent } from "./check-photo/check-photo.component";
const routes: Routes = [
{ path: "", component: GlownaComponent },
{ path: "checkPhoto", component: CheckPhotoComponent }
];
@NgModule({
imports: [NativeScriptRouterModule.forRoot(routes)],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule {}
解决方案
推荐阅读
- php - 我的 heroku 应用程序没有运行测功机 - 没有运行 Web 进程意味着打开托管网站时出现应用程序错误
- vue.js - GeoLocation 无法将坐标传递给另一个变量
- java - javafx.fxml.LoadException 无法运行 .java
- graphql - Apollo GraphQL:使用 withFilter 时修改有效负载?
- vba - 有没有办法根据模块中子例程的数量动态地将项目添加到表单中?
- postgresql - 在 PostgreSQL 中聚合和连接两个表
- r - 生成一个新列,计算 R 中其他两列之间共享单词的数量?
- sql - How to connect multiple check boxes in Access 2016 to column in SQL Server?
- javascript - 如何搜索包括下拉选项?
- php - 无法在模块 laravel 中获取可邮寄的路径