使用 Reactive Forms 时,包含无效的 FormControl(无效表单)的 formGroup 显示为无效,这是正常的,但不包含任何错误。
我应该能够从 formGroup.errors 中的表单中获取所有错误,但它为空
但是,表单状态无效,并且在每个无效的 formControl 下,它都会给我验证错误我错过了什么?
检查错误:
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl, Validators } from "@angular/forms";
import { DB1 } from 'src/app/interfaces/IDB';
import { DBS } from 'src/app/consts';
@Component({
selector: 'app-new-dashboard',
templateUrl: './new-dashboard.component.html',
styleUrls: ['./new-dashboard.component.scss']
})
export class NewDashboardComponent implements OnInit {
dbs: string[] = ["DB1", "DB2"]
selectAxisOptions:string[] = []
newDashboardForm = new FormGroup({
name: new FormControl(null, [Validators.required]),
db: new FormControl(null, [Validators.required]),
axis: new FormControl({ value: null, …Run Code Online (Sandbox Code Playgroud) 我正在使用套接字 io 和烧瓶应用程序。除了我总是收到此消息外,一切正常。这是我的初始化:
app = Flask(__name__)
app.config['SECRET_KEY'] = APP_SECRET_KEY
jwt = JWTManager(app)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
# app.config['transports'] = 'websocket'
socketio = SocketIO(app, cors_allowed_origins="*", async_mode='threading')
socketio.run(app, debug=True)
Run Code Online (Sandbox Code Playgroud)
什么可能导致此警告,它是什么意思?
我正在尝试将我的代码分成文件。当我尝试从另一个文件导入任何变量时,出现以下错误:
File ".\app.py", line 2, in <module>
from backend.Measure import Measure,MeasurementSchema,measure_schema,measures_schema
ModuleNotFoundError: No module named 'backend'
Run Code Online (Sandbox Code Playgroud)
我有3个文件:
应用程序.py
from flask import Flask, Request, jsonify
from backend.Measure import Measure,MeasurementSchema,measure_schema,measures_schema
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
@app.route('/api/measures')
def getAllMeasurements():
results = Measure.query.all()
return measures_schema.jsonify(results)
Run Code Online (Sandbox Code Playgroud)
测量.py
from flask_marshmallow import Marshmallow
from backend.app import app
from backend.app import db
ma = Marshmallow(app)
class Measure(db.Model):
__tablename__ = 'measurements'
id = db.Column(db.Integer, primary_key=True)
timestamp = db.Column(db.DateTime, auto_now_add=True)
temperature = db.Column(db.Float)
def __init__(self, …Run Code Online (Sandbox Code Playgroud)最近发现了这个库:https : //easy-peasy.now.sh/ 实现了,不得不说还不错。为什么它不像 redux 那样受欢迎?为什么人们在可以使用它时倾向于使用 redux?两者的优点和缺点是什么?还想知道当我可以做这样的事情时,状态的不变性是如何在 easy peasy 中保持的:
addProduct: action((state, payload) => {
state.productIds.push(payload);
})
Run Code Online (Sandbox Code Playgroud)
显然它会改变状态.. 也许它不会改变实际状态?一般想知道是否保留了所有 redux 原则,以及两者之间的主要区别是什么?
我正在使用 Flask SocketIO 这是我在服务器中的启动文件:
app = Flask(__name__)
app.config['SECRET_KEY'] = APP_SECRET_KEY
JWTManager(app)
CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
app.config['transports'] = 'websocket'
app.config['JSON_SORT_KEYS'] = False
socketio = SocketIO(app, cors_allowed_origins="*")
socketio.run(app, host=SERVER_IP, debug=True)
Run Code Online (Sandbox Code Playgroud)
我有一个简单的路由,它向客户端发出一条消息,表明其目的是触发客户端向服务器发送一段代码,该代码将允许服务器退出 while 循环并继续执行该路由。路线如下:
@app.route('/socket')
def send_socket():
socketio.emit('custom', {'data': 123})
code = ''
while not code :pass
// another logic here - after code received
Run Code Online (Sandbox Code Playgroud)
在客户端中我订阅该事件:
socket.on('custom', (data) => {
// emit the code to the server
});
Run Code Online (Sandbox Code Playgroud)
我还有一个按钮可以触发对服务器 /socket 路由的 api 请求:
const response = await axios
.get('http://serverip:5000/socket')
.catch((error: AxiosError) => { …Run Code Online (Sandbox Code Playgroud) flask ×2
socket.io ×2
angular ×1
easy-peasy ×1
immutability ×1
import ×1
python ×1
react-native ×1
react-redux ×1