小编efa*_*ley的帖子

THREE.js 轨道控制不起作用

我正在尝试学习三,到目前为止一切进展顺利。我正在努力创建一个简单的项目,在高尔夫球座上建造一个高尔夫球。最终,我会将它放在一个天空盒中,并使用一些着色器来创建球中凹痕的外观。

现在我已经能够创建球和发球台并设置相机和灯光。我现在正在尝试添加一些轨道控件,以便我可以在场景周围旋转、平移和缩放。我添加了orbitControls 脚本并设置了我在在线示例中看到的方式。但是,当我尝试绕轨道运行时,我的相机会捕捉到 1,0,0 0,1,0 或 0,0,1,最终场景完全失败,我最终沿着 0,0 看,没有任何物体可见。

这是我的完整代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8>
        <title>3D Sandbox</title>
        <style>
            html, body {
                margin: 0px;
            }
            canvas {
                background-color: #999;
                position: absolute;
                height: 100vh;
                width: 100vw;
                overflow: hidden;
            }
        </style>
    </head>
    <body>
        <script src='/three.js'></script>
        <script src="/orbitControls.js"></script>
        <script type='text/javascript'>
            let scene, 
                camera, 
                controls,
                renderer,
                height = window.innerHeight,
                width = window.innerWidth;

            window.addEventListener('load', init, false);

            function init () {
                createScene();
                createCamera();
                createLights();
                createBall();
                createTee();
                render();
                animate();
            }

            function createScene () {
                let grid;

                scene …
Run Code Online (Sandbox Code Playgroud)

three.js

3
推荐指数
2
解决办法
9050
查看次数

Angular 2(RC1)无法读取null的属性'isSkipSelf'

我有一个棱角分明的应用程序,经过一些最近的重构,我收到了一个我不知道的新的神秘错误消息。

例外:错误:未捕获(在承诺中):TypeError:无法读取null的属性'isSkipSelf'

当我在构造函数中将变量类型设置为服务(ProductMeshGradientService)时,开始发生此错误。如果我在构造函数中删除了引用,则该应用程序将按预期工作。

总结代码:

服务中断 注:productMeshGradientService由于调试原因,我目前根本没有使用。因此,我可以确认该错误与使用服务无关,而是由仅将变量设置为服务类型引起的。无论是HttpProductImageTextureServices引起任何问题。

import {
  Injectable,
  EventEmitter
} from '@angular/core';
import {
  Http,
  Response
} from '@angular/http';

import { ProductMeshGradientService } from '../../services/product.mesh-gradient/product.mesh-gradient.service';

@Injectable()
export class TextureService {
    constructor( 
        private http: Http,
        private productMeshGradientService: ProductMeshGradientService ,
        private productImageTextureService: ProductImageTextureService) { }
    // Some methods are here.
}
Run Code Online (Sandbox Code Playgroud)

正在导入(缩写)的服务注意:此文件存在非常相似的问题,因为如果我删除了在构造函数中设置的变量,则错误会消失。唯一的区别是在此文件中,我需要同时删除productServiceproductCanvasService

import { Injectable } from '@angular/core';

import { ProductService } from '../product/product.service';
import { …
Run Code Online (Sandbox Code Playgroud)

angular

3
推荐指数
1
解决办法
6973
查看次数

从 clientLeft、clientTop、offsetLeft 和 offsetTop 获取元素位置的错误值

我试图返回元素的位置,但由于某种原因,左侧和顶部的客户端、滚动和偏移值总是错误的。这里的目标是确定用户是否单击了下拉元素的外部以及是否关闭了它,因此我需要元素的准确位置来与单击位置进行比较。

例如,我使用标尺检查了元素的位置,它读取的左侧值为 1013 像素,顶部值为 484 像素。但是,当我在代码中获取元素并检查 offsetLeft 时,值是 3,offsetTop 是 16。这是怎么回事?看起来我正在获取相对于父级而不是文档的位置。

我使用 Angular 并使用组件中的模板引用获取元素。

dropdown.component.ts

@ViewChild('dropdown') dropdown: any; // Template reference to the element

constructor(
  private elementRef: ElementRef // Reference to the :host element
} { }

ngOnDestroy() {
  this.elementRef.nativeElement.removeEventListener('click', this.handleClick.bind(this));
}

ngOnInit() {
  this.subscribeToClickEvent();
}

private handleClick(event: MouseEvent): void {
  // this.dropdown.nativeElement.clientLeft equals 0
  // this.dropdown.nativeElement.clientTop equals 0
  // this.dropdown.nativeElement.offsetLeft equals 3
  // this.dropdown.nativeElement.offsetTop equals 16
  // this.dropdown.nativeElement.scrollLeft equals 0
  // this.dropdown.nativeElement.scrollTop equals 0
  // Left should equal ~1013 …
Run Code Online (Sandbox Code Playgroud)

javascript angular

2
推荐指数
1
解决办法
3422
查看次数

角表单控件禁用绑定不起作用

我有一个窗体控件,该控件在页面加载时会禁用。当用户单击一个按钮时,表单应启用编辑功能。但是,当我切换禁用控件的属性时,什么也不会发生。

模板

<form [formGroup]='accountForm'>
  <md-input-container>
    <input mdInput formControlName='name' />
  </md-input-container>
  <button (click)='isEditing = !isEditing'>Edit</button>
</form>
Run Code Online (Sandbox Code Playgroud)

零件

export class AccountComponent {
  private accountForm: FormGroup;
  private isEditing = false;
  private name: FormControl = new FormControl({ value: '', disabled: !isEditing; 

  constructor(
    formBuilder: FormBuilder
  ) {
    this.accountForm = formBuilder.group({
      'name': this.name
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

angular angular-forms

1
推荐指数
2
解决办法
1万
查看次数

Angular 5属性指令将mat-ripple添加到host元素

如何将mat-ripple指令添加到我创建的自定义指令的host元素中?关键是要mat-ripple自动添加到我添加的任何元素my-custom-directive.

因此,如果我添加<button my-custom-directive>Button</button>到模板,它应该被渲染为,<button my-custom-directive mat-ripple mat-ripple-color="#000">Button</button> 而不必每次我使用时都输入所有这些my-custom-directive.作为一个例子,看看如何mat-raised-button工作.你只需添加该指令就mat-ripple可以了.我想用我自己的按钮复制它.

这不起作用.

HTML

<button my-custom-directive>Button</button>
Run Code Online (Sandbox Code Playgroud)

指示

@Directive({
  selector: ['appMyCustomDirective']
})
export class MyCustomDirective implements AfterViewInit {
  constructor(
    private renderer: Renderer,
    private element: ElementRef
  ) { }

  ngAfterViewInit() {
    this.renderer.setElementAttribute(this.element.nativeElement, 'mat-ripple', '');
    this.renderer.setElementAttribute(this.element.nativeElement, 'mat-ripple-color', '#000000');
  }
}
Run Code Online (Sandbox Code Playgroud)

我也试过注入MatRipple指令并调用MatRipple.launch(...)但是这会产生一个涟漪效应,它不会被限制在按钮内部,并且不会应用与mat-ripple通过模板直接添加到元素时相同的颜色.

angular-directive angular

1
推荐指数
1
解决办法
4003
查看次数

passportJS serializeUser 和 deserializeUser 从未调用过

我试图弄清楚我在这里做错了什么。在查看文档(可悲的是已经过时)并搜索网络后,我相信我已经正确配置了护照的所有内容,但由于某种原因,serializeUser 和 deserializeUser 都没有被调用,这导致 req.user 永远不会被设置。

好的,这是我的根 server.js 文件(总结)

/**
 * Module dependencies
 */

var express = require('express'),
    app = module.exports = express(),
    bodyParser = require('body-parser'),
    cookieParser = require('cookie-parser'),
    env = process.env.NODE_ENV || 'development',
    errorHandler = require('errorhandler'),
    http = require('http'),
    methodOverride = require('method-override'),
    morgan = require('morgan'),
    passport = require('passport'),
    path = require('path'),
    routes = require('./server/routes/index'),
    secret = process.env.SESSION_SECRET,
    session = require('express-session'),
    FileStore = require('session-file-store')(session);

/**
 * Configuration
 */

// all environments
app.set('http-port', process.env.PORT || 3000);
app.set('views', __dirname + '/public');
app.engine('.html', …
Run Code Online (Sandbox Code Playgroud)

node.js express passport.js

0
推荐指数
1
解决办法
1671
查看次数

Angular Material 5设置fab按钮默认颜色

我正在使用Anuglar材质(5.0.4),并且我希望mat-fab-button默认的背景颜色是白色,就像Angular示例中一样。但是对我来说,由于某种原因,背景色是强调色。

在此处输入图片说明

的HTML

<h2>Fab Buttons</h2>
<div>
  <button mat-fab>Basic</button>
  <button mat-fab color="primary">Primary</button>
  <button mat-fab color="accent">Accent</button>
  <button mat-fab color="warn">Warn</button>
  <button mat-fab disabled>Disabled</button>
  <button mat-fab>
    <mat-icon aria-label="Example icon-button with a whats hot icon">whatshot</mat-icon>
  </button>
  <a mat-fab routerLink=".">Link</a>
</div>

<h2>Mini Fab Buttons</h2>
<div>
  <button mat-mini-fab>Basic</button>
  <button mat-mini-fab color="primary">Primary</button>
  <button mat-mini-fab color="accent">Accent</button>
  <button mat-mini-fab color="warn">Warn</button>
  <button mat-mini-fab disabled>Disabled</button>
  <button mat-mini-fab>
    <mat-icon aria-label="Example icon-button with a whats hot icon">whatshot</mat-icon>
  </button>
  <a mat-mini-fab routerLink=".">Link</a>
</div>
Run Code Online (Sandbox Code Playgroud)

主题

$deeporange-teal-amber-theme-primary: mat-palette($mat-deep-orange, 500, 100, 700);
$deeporange-teal-amber-theme-accent: mat-palette($mat-teal);
$deeporange-teal-amber-theme-warn: …
Run Code Online (Sandbox Code Playgroud)

floating-action-button angular-material angular

0
推荐指数
1
解决办法
5358
查看次数