我是angualr 2的新手.我正在做一个小练习.我有一个用户在登录时对用户进行身份验证的服务.这是它的登录功能.
login(email:string, password:string){
var loginrul="https://filing.herokuapp.com/api/v1/auth/login/";
return this.http.post(loginrul,JSON.stringify({ password: password,email: email }),
{headers:new Headers({'Content-Type':'application/json'})}
).map(res=>res.json()).
subscribe(
data => localStorage.setItem('id_token',data.auth_token),
error=>console.log(error)
);
}
Run Code Online (Sandbox Code Playgroud)
当我在组件中调用此函数时,angualr会给出"属性订阅不存在于'订阅'上的错误".
doLogin(event) {
console.log(event);
console.log(this.loginForm.value);
let formData = this.loginForm.value;
let email = this.loginForm.controls.email.value;
let password= this.loginForm.controls.password.value;
this.auth.login(email,password).subscribe(res =>{
console.log(res);
if(res.status===200){
this.router.navigate(['dashboard']);
}
}
)
}
Run Code Online (Sandbox Code Playgroud)
我认为为什么angular会出现这个错误,因为我在登录功能中使用订阅以及在调用登录功能时.请建议一些解决方案或替代方法来实现我在登录功能中尝试实现的结果.
我正在使用djoser进行身份验证.我想自定义djoser的创建用户端点.我有一个用户应用程序.这是我的用户模型
from django.db import models
class User(models.Model):
email = models.CharField(max_length=100, blank=False)
name = models.CharField(max_length=100, blank=False)
last_name = models.CharField(max_length=100, blank=False)
account_address = models.CharField(max_length=30, blank=False)
password = models.CharField(max_length=100, blank=False)
Run Code Online (Sandbox Code Playgroud)
这是我的序列化器
from rest_framework import serializers
from User.models import User
class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ('url', 'id', 'email', 'name', 'last_name', 'account_address', 'password')
Run Code Online (Sandbox Code Playgroud)
我的User.urls.py看起来如下
from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter
from .views import UserViewSet
router = DefaultRouter()
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^account/', include('djoser.urls')),
]
Run Code Online (Sandbox Code Playgroud)
和项目的url.py正在关注
from django.contrib …
Run Code Online (Sandbox Code Playgroud) 我试图按照以下方式根据条件来对组件进行样式设置。
<div class="col-md-3 d-flex justify-content-center align-items-center" ng-style ="{ ' background-color' : (vars.state=='Signup')? '#73c7af' : '#ffffff' }">
Run Code Online (Sandbox Code Playgroud)
和我的vars.state = Signup。因此,根据该div的背景,它应该是#73c7af,但它仍然是白色的。有人可以告诉我我在哪里犯错吗?
我正在尝试从浏览器读取cookie,以设置authguard。我正在尝试检查是否已设置cookie,然后用户已登录,否则未登录。为此,我正在使用ngx-cookie-service。这是从Cookie获取价值的代码。
import {UserAuthService} from '../services';
import { CookieService } from 'ngx-cookie-service';
@Injectable()
export class AuthService {
constructor(
private cookieService: CookieService,
}
getSessionid() {
this.cookieService.set('test', '123');
console.log(this.cookieService.get('test'));
console.log(this.cookieService.get('sessionid'));
console.log(this.cookieService.get('csrftoken'));
console.log(this.cookieService.get('messages'));
return this.cookieService.get('sessionid') || null;
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,它在控制台中正确打印了某些值,例如test和csrftoken,但是message和sessionid为空白,在应用程序选项卡中,我可以看到所有cookie。这是我的应用程序选项卡的屏幕截图。
有人知道这里怎么了吗?
我有趣的是 PIL 在里面写一些文本和图像,然后将其保存在同一位置。以下是我执行此操作的函数
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
def add_text_to_image(image_path):
img = Image.open(image_path)
img = img.convert('RGB')
widht, height = img.size
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("helvetica.ttf", 20)
draw.text((0, 0), "Some text", (0, 0, 0), font=font)
img.save(image_path)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误。
回溯(最近一次调用最后一次):文件
“/usr/local/lib/python3.6/site-packages/background_task/tasks.py”,
第 43 行,在 bg_runner func(*args, **kwargs) 文件中
“/home/paksign/app/app/document/tasks.py”,第 74 行,位于
文档状态已更改为已完成
add_branding_texts_to_document_images(元)文件
“/home/paksign/app/app/document/utils.py”,第 277 行,位于
快照中的快照的 add_branding_texts_to_document_images:文件
“/home/paksign/app/app/document/utils.py”,第 270 行,位于
add_text_to_image img.save(image_path) 文件
“/usr/local/lib/python3.6/site-packages/PIL/Image.py”,第 1994 行,位于
保存 save_handler(self, fp, filename) 文件
“/usr/local/lib/python3.6/site-packages/PIL/JpegImagePlugin.py”,行
第761章 _save …
我正在尝试使用 docker run 命令通过 Dockerfile 运行 docker 容器。以下是我的 Dockerfile。
FROM python:3.6
# for imaging stuff
RUN apt-get update
RUN apt install libmagickwand-dev
# Create app directory
RUN mkdir -p /home/test/app
# Install Libre Office and ghostscript for pdf conversion and repairing
RUN apt-get update -qq \
&& apt-get install -y -q libreoffice \
&& apt-get remove -q -y libreoffice-gnome \
&& apt-get update \
&& apt-get -y install ghostscript \
&& apt-get -y install nano \
&& apt-get -y install …
Run Code Online (Sandbox Code Playgroud) i am trying to ssh into a remote host and then execute certain commands on the remote host's shell. Following is my pipeline code.
pipeline {
agent any
environment {
// comment added
APPLICATION = 'app'
ENVIRONMENT = 'dev'
MAINTAINER_NAME = 'jenkins'
MAINTAINER_EMAIL = 'jenkins@email.com'
}
stages {
stage('clone repository') {
steps {
// cloning repo
checkout scm
}
}
stage('Build Image') {
steps {
script {
sshagent(credentials : ['jenkins-pem']) {
sh "echo pwd"
sh 'ssh -t -t ubuntu@xx.xxx.xx.xx -o …
Run Code Online (Sandbox Code Playgroud) 我试图从请求中获取Blob响应,然后从该Blob生成一个URL,并将此URL设置为图像的源。
但是图像未加载。
这是我的HTML:
<img src="{{previewSignsrc}}" alt="Sign Thumbnail">
Run Code Online (Sandbox Code Playgroud)
这是我的.ts
文件:
this.signModalDataService.getPreviewSignature({'name': this.SignatureName, 'font_type': 0});
this.signModalDataService.previewSignature
.subscribe((res) => {
console.log(res);
let blob = new Blob([res['_body']], {type: 'image/png'});
this.previewSignsrc = URL.createObjectURL(blob);
this.showPreviewSign = true;
});
Run Code Online (Sandbox Code Playgroud)
我使用相同的方法进行设置url
,ng2-pdfviewer
效果很好。
我有一项服务从服务器获取一些数据并更新一些主题,在我的组件的 ngOnInit 函数中我正在订阅该主题。我已确认主题已正确更新。
以下是我的服务功能,它从服务器获取数据并更新主题。
getInboxData(id?) {
this.inboxID = id;
this.loadingData.next( // tells to start showing loading animation
{
showloading: true,
clearDocuments: this.shouldClearDocuments()
});
this.getInboxCount();
this.dashboardService.getInbox(id, this.page)
.subscribe((response) => {
for (const inbox of response['results']) {
this.documents.push(inbox.document);
// tells to stop showing loading animation
this.loadingData.next({showloading: false, clearDocuments: this.shouldClearDocuments()});
}
if (response.next != null) {
this.page++;
// this.getInboxData(id);
}else {
this.page = 1; // reset
}
this.documentsData.next(response);
});
}
Run Code Online (Sandbox Code Playgroud)
我正在我的组件中订阅documentsData
。以下是组件的代码。
ngOnInit() {
this.dashboardDataService.getInboxData();
this.dashboardDataService.documentsData
.subscribe((response) => {
this.isLoadingMoreResult = false; …
Run Code Online (Sandbox Code Playgroud) 我有一个问题 div,它使用 ngFor 生成一些子组件。这些子组件具有用于数据的输入字段。当用户在这些字段中输入数据并单击下一个按钮时,问题 div 会被 ngIf 隐藏并显示预览 div。当再次按下后退按钮时,预览 div 会与 ngIf 一起隐藏并出现问题 div。但是因为问题 div 中的子组件再次创建,所以输入字段中的数据消失了。以下是我的html
<!-- questions
div-->
<div class="questions activity_screen" *ngIf="showquestions">
<div *ngFor="let component of components;let i=index">
<app-termhost #cmp [term] = component [title]="component.title" [Qnumber]="i+1"></app-termhost>
</div>
<a class="submit_button" (click)="getdata()">Submit</a>
</div>
<!-- preview div-->
<div style="width: 100%;height: 100%;display: flex;align-content: center;justify-content: center" class="preivew" *ngIf="showpdf">
<button (click)="goback()">go back</button>
</div>
Run Code Online (Sandbox Code Playgroud)
如何保持这些组件的先前状态,以便在按下后退按钮后再次出现问题 div 后数据不会丢失!
angular2-forms angular2-directives angular2-template angular
angular ×6
cookies ×1
django ×1
docker ×1
docker-build ×1
docker-run ×1
dockerfile ×1
javascript ×1
jenkins ×1
jenkins-cli ×1
observable ×1
python ×1
rxjs ×1
typescript ×1