我是 Angular 和 Deployd 的新手,想知道如何一起使用它们。
我发现 Deployd 网站中的示例很好,但它只消耗其余 API 数据,我想了解如何将 Deployd 作为 AngularJS 中的服务。例如,通过部署中可用的收集事件,使所有客户端 API 保持最新的收集最新数据。
我想出了下面的示例,我们可以看到我正在使用 $resource 来使用其余 api,但在控制器“MyCtrl”内,我正在调用 dpd,我想用它来利用功能,例如http://docs.deployd.com/docs/collections/notifying-clients.md
我真的很想看到一些例子,或者对此有任何建议!
感谢您的浏览:)
angular.module('questions', ['ngResource'])
.factory('Deployd', function(dpd){
return dpd;
})
.factory('EntriesService', function($resource){
return $resource('/entries', {});
})
.controller('MainCtrl', ['$scope', 'EntriesService', function($scope, EntriesService) {
$scope.title = "Q&A Module";
$scope.entries = [];
EntriesService.query(function(response){
$scope.entries = response;
});
$scope.addMessage = function() {
$scope.entries.push({
author: "myAuthor",
message: $scope.message
});
EntriesService.save({
author: "myAuthor",
message: $scope.message
});
};
dpd.comments.get(function(comments, error) {
comments.forEach(function(comment) {
console.log(comment);
});
}); …Run Code Online (Sandbox Code Playgroud) 目前正在为一个运行 React v15 的项目做维护。升级了 Webpack 3 > 4、Babel 6 > 7、css-loader 0.28.x > 3.0.0 等。
最初,更新 React 并使用所有 react-codemod + jscodeshift 转换 js 文件。虽然那个阶段的版本不稳定,但它加载并显示了正确的样式等。
我觉得奇怪的是,在更新 file-loader、css-loader、babel 和相关包后,我一直得到Module not found: Error: Can't resolve,如下所示:
ERROR in ./app/sharedComponents/TitleGeneric/style.css (./node_modules/css-loader/dist/cjs.js??ref--6-1!./app/sharedComponents/TitleGeneric/style.css)
Module not found: Error: Can't resolve './sharedStyles/typography.css' in '/Users/userX/www/my-project-ui/app/sharedComponents/TitleGeneric'
resolve './sharedStyles/typography.css' in '/Users/userX/www/my-project-ui/app/sharedComponents/TitleGeneric'
using description file: /Users/userX/www/my-project-ui/package.json (relative path: ./app/sharedComponents/TitleGeneric)
Field 'browser' doesn't contain a valid alias configuration
using description file: /Users/userX/www/my-project-ui/package.json (relative path: ./app/sharedComponents/TitleGeneric/sharedStyles/typography.css)
no extension
Field 'browser' doesn't contain a …Run Code Online (Sandbox Code Playgroud) 在处理 React-hook-form 时进行输入字段匹配验证的最佳实践是什么?例如,匹配email输入时等。
在使用 React-hook-form 查看电子邮件匹配验证时,在尝试通过验证方法将错误消息与“耦合元素”分开时发现了一个问题。在ref只需要一个用于阵营钩形件形成一个参数register,而需要使用useRef访问current.value为值匹配,如下所示:
import React, { useRef } from "react";
import ReactDOM from "react-dom";
import { useForm } from "react-hook-form";
function App() {
const { register, handleSubmit, errors } = useForm();
const inputEmail = useRef(null)
const onSubmit = data => {
console.log('onSubmit: ', JSON.stringify(data))
}
return (
<form onSubmit={handleSubmit(onSubmit)}>
<label htmlFor="email">Email</label>
<input
name="email"
type="email"
ref={inputEmail}
/>
{/* desired: show `email` error message */}
<label htmlFor="email">Email confirmation</label>
<input …Run Code Online (Sandbox Code Playgroud) 我最近遇到需要编写 a 的 Mock Class,因为它会导致 SwiftUIpreview无法工作。不幸的是,我收到错误:
Property type 'T' does not match that of the 'wrappedValue' property of its wrapper type 'EnvironmentObject'
Run Code Online (Sandbox Code Playgroud)
在视图结构中:
struct ContentView<T>: View {
@EnvironmentObject var mockFoobar: T
...
}
Run Code Online (Sandbox Code Playgroud)
还有错误:
Type of expression is ambiguous without more context
Run Code Online (Sandbox Code Playgroud)
对于预览结构:
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
let mockFoobar: MockFoobar = MockFoobar()
return ContentView<MockFoobar>()
.environmentObject(mockFoobar)
}
}
Run Code Online (Sandbox Code Playgroud)
MockFoobar 类是:
class MockFoobar: ObservableObject {
...
}
Run Code Online (Sandbox Code Playgroud)
正如用户@Asperi 善意提供的,按照建议测试了以下内容:
class Foobar: ObservableObject { …Run Code Online (Sandbox Code Playgroud) 对于下面的代码,我期待控制台 2 和 3 使用“Jupiter”,但是即使我传递了不同的上下文,也会将其绑定到全局窗口对象。
function otherScope () {
this.sectionHeight = "Jupiter"
}
(function () {
var sectionHeight = "Mars";
(function () {
setTimeout(function () {
console.log('console 1', sectionHeight)
})
}())
}())
window.sectionHeight = "cool!";
(function () {
setTimeout(function () {
console.log('console 2', sectionHeight)
})
}.bind(otherScope)())
setTimeout(function () {
console.log('console 3', sectionHeight)
}.bind(otherScope))
setTimeout(function () {
console.log('console 4', sectionHeight)
})Run Code Online (Sandbox Code Playgroud)
我想开始正确组织我的代码,所以我想使用对象文字.在下面的例子中,我正在做一个伪类.我希望它init()可以作为构造函数,但不幸的是,我没有看到如何基于对象上下文设置属性.
var car = {
context : this,
wheels : 0,
color : '',
speed : 0,
init : (function(x){
console.log(x);
x.wheels = 4;
x.color = 'red';
x.speed = 120;
})(context)
};
console.log(car.color);
Run Code Online (Sandbox Code Playgroud) 使用的setInterval或RequestAnimationFrame,我想从X和Y之间lerping假设X是0,Y是1取得进展的价值,我想有0它开始,在半0.5和1时结束时.我希望在给定的时间范围内发生这种情况,比方说5秒钟.这意味着当setInterval/RequestAnimationFrame达到2.5秒时,将发生半值0.5.最后,我想pingPong,所以当它达到5秒时,值正在减少而不是增加,例如0.9,0.8,0.7等,然后从0,0.1,0.2再次开始......
任何提示或建议?
谢谢!
我找不到理解和解决这个问题的方法,而且我做了很多.
我有一个脚本,希望是一个简单的表单,通过POST发送文件.第二个文件,处理信息.
默认情况下,我向用户提供了一些字段,其中一个字段是"file"类型的输入字段,还有一些"隐藏"字段,这使我可以在POST上使用值.
我发现,当添加类型为"file"的新输入时,$ _POST返回数组0,即使$ _FILES也不返回任何内容.我不知道如何解决这个问题,并且在保持"file"类型的默认输入框时它可以正常工作.
<form id="formulario" enctype="multipart/form-data" action="projectos_processar.php" method="POST">
Modo inserir projecto item!<br/><br/>
<label>Imagem de apresentacao: </label>
<input id="img_p_child" type="file" name="img_p_child" cols="100" value="" class="validate['required','image']" /><br/>
<br/>
<br/>
<input type="file" id="video" name="video" class="validate['required','video']" cols="100">
<br/>
<br/>
<hr>
Publicar o item ? <br/>
<br/>
<br/>
Sim <input type="radio" name="published" value="1"><br>
Nao <input type="radio" name="published" value="0" checked="true"><br>
<hr>
<!-- INICIO:: CAMPOS EM MODO HIDDEN -->
<input type="hidden" value="center" name="crop_X_Y" />
<input type="hidden" value="assets/publicidade/FURIOUS01/" name="stringDirPagina" />
<input type="hidden" value="128" name="parent_id" />
<input …Run Code Online (Sandbox Code Playgroud) javascript ×4
reactjs ×2
angularjs ×1
closures ×1
css-loader ×1
deployd ×1
file-upload ×1
lerp ×1
php ×1
scope ×1
settimeout ×1
swiftui ×1
this ×1
webpack ×1
xcode ×1
xcode11.4 ×1