我对AngularJS和指令的一个非常基本的例子有一个问题.我想创建一个使用webrtc显示网络摄像头图像的指令.我的代码完美地显示了流,但如果我添加超时(例如刷新画布),$ timeout不起作用,这就是代码:
wtffDirectives.directive('scannerGun',function($timeout){
return {
restrict: 'E',
template: '<div>' +
'<video ng-hide="videoStatus"></video>' +
'<canvas id="canvas-source"></canvas>' +
'</div>',
replace: true,
transclude: true,
scope: false,
link: function postLink($scope, element){
$scope.canvasStatus = true;
$scope.videoStatus = false;
width = element.width = 320;
height = element.height = 0;
/* this method draw the webcam image into a canvas */
var drawVideoCanvas = function(){
sourceContext.drawImage(vid,0,0, vid.width, vid.height);
};
/* start the timeout that take a screenshot and draw the source canvas */
var update = function(){ …Run Code Online (Sandbox Code Playgroud) 我有以下服务
@Injectable()
export class PService {
private loadPComponent: ComponentPortal<PComponent>;
private bodyPortalHost: DomPortalHost;
constructor(private appRef: ApplicationRef,
private componentFactoryResolver:
ComponentFactoryResolver,
private injector: Injector) {
this.loadPComponent = new ComponentPortal(PComponent);
}
instance(elementRef: Element) {
this.bodyPortalHost = new DomPortalHost(elementRef,
this.componentFactoryResolver, this.appRef, this.injector);
}
show() {
const componentRef: ComponentRef<PComponent> =
this.bodyPortalHost.attach(this.loadPComponent);
}
hide() {
this.bodyPortalHost.detach();
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我有一个名为“PComponent”的组件,并且从该服务中动态创建该组件,该类有两个方法实例 - 传递调用服务显示的组件的元素 - 附加已“创建”的 PComponent
一切正常,Portal 是一个很棒的解决方案!但我的 PComponent 有一个带有一些变量的 HTML 模板,例如,
{{ 图像URL }}
这应该是一个图像 url 并将该图像显示到 PComponent 中的 div 内容中。 问题 我如何将 imageURL 字符串传递到服务或组件中?
提前致谢
首先,我是Rust的新手:-)
问题:我想创建一个名为RestServer的模块,其中包含添加路由并启动服务器的方法(actix-web)。
struct Route
{
url: String,
request: String,
handler: Box<dyn Fn(HttpRequest) -> HttpResponse>
}
impl PartialEq for Route {
fn eq(&self, other: &Self) -> bool {
self.url == other.url
}
}
impl Eq for Route {}
impl Hash for Route {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.url.hash(hasher);
}
}
Run Code Online (Sandbox Code Playgroud)
这是路由结构,此结构包含路由URL,请求类型(GET,POST等),而hanlder是必须捕获请求并返回HTTPResponse的函数
pub struct RestServer
{
scopes: HashMap<String, Rc<HashSet<Route>>>,
routes: HashSet<Route>,
host: String,
}
impl RestServer {
pub fn add_route(self, req: &str, funct: impl Fn(HttpRequest) -> HttpResponse + 'static, …Run Code Online (Sandbox Code Playgroud) actix-web ×1
angular ×1
angular-cdk ×1
angularjs ×1
borrowing ×1
javascript ×1
portal ×1
rust ×1
timeout ×1