我正在使用ui-router 0.2.8.我想根据设备宽度加载模板.我可以毫无问题地获得设备宽度,将其设置在范围等,但我可以弄清楚如何将它绑定到$ stateParams.我在另一个控制器中有范围变量,可以访问状态控制器,它只是状态本身不可用.我已经尝试过templateProvider,但这只是给我一个字符串.我还能尝试什么来使其工作?
.state('list', {
abstract: true,
url: "/list",
templateUrl: 'views/'+$stateParams.somevalue+'/page.html',
controller: "myCtrl"
})
.state('list.first', {
url: "/first",
templateUrl: "views/first.html"
})
Run Code Online (Sandbox Code Playgroud) 我正在使用带有React的typescript 2.3.4.我收到错误TS2339:错误TS2339:属性'name'在类型'Readonly <{children?:ReactNode; }>&Readonly <{}>'.当我尝试在子组件中声明属性时发生错误.如何在子组件中正确引用该属性?
由于某种原因,代码没有在脚本运行器中执行.
任何帮助表示赞赏.
export interface person {
name: string;
age: number;
}
interface State {
personArray: person[];
}
interface Props {
}
class ProfileData extends React.Component<{}, person> {
public render() {
return (
<section>
<section>
<h3>profile 1</h3>
<div>{this.props.name}</div>
</section>
</section>
)
}
}
export class Profile extends React.Component<Props, State> {
public state: State;
public props: Props;
constructor(props: Props){
super(props);
this.state = {
personArray: [
{
name: 'bazaaa',
age: 42
},
{
name: 'louis',
age: 24
} …Run Code Online (Sandbox Code Playgroud)我有一个lambda,我想为它编写单元测试.我正在使用异步等待,但我遇到了解决承诺的问题.我想测试不同的条件,我如何编写测试来解决并停止查看超时?
提前致谢.
错误:超出2000ms的超时.对于异步测试和挂钩,确保调用"done()"; 如果返回Promise,请确保它已解决.
---单位
describe('tests', function() {
describe('describe an error', () => {
it('should return a 500', (done) => {
handler('', {}, (err, response) => {
expect(err.status).to.eq('failed')
done()
})
})
})
});
Run Code Online (Sandbox Code Playgroud)
- 处理程序
export const handler = async (event, context, callback) => {
return callback(null, status: 500 )
})
Run Code Online (Sandbox Code Playgroud) 刚升级到Angular 2.1.我有一个@input值,我试图传递一个数组.一旦我将*ngIf放入模板中,我就会得到解析错误?如果我打印输入值我得到:// [对象对象],[对象对象],[对象对象].为什么这会影响*ngIf?
<div *ngIf="< my value "></div>
Run Code Online (Sandbox Code Playgroud)
- error zone.js?fad3:388未处理的Promise拒绝:模板解析错误:无法绑定到'ngIf',因为它不是'div'的已知属性.("
我从反应组件中得到了一个ts错误.组件运行正常,构建等,但是typescript在ide中显示错误.不知道我需要如何声明这个以消除错误.我试图在组件本身内部创建一个setState方法,但这会产生更多错误.
错误:(15,19)TS2605:JSX元素类型'Home'不是JSX元素的构造函数."Home"类型中缺少属性"setState".
"typescript":"^ 2.3.4",
"反应":"^ 15.5.4",
"react-dom":"^ 15.5.4",
!----
export class App extends React.Component<Props, State> {
public state: State
public props: Props
constructor(props: Props) {
super(props)
this.state = {
view: <Home />, <<<<
}
Run Code Online (Sandbox Code Playgroud)
- 其余部分为简洁而删除
export class Home extends React.Component<Props, State> {
public state: State;
public props: Props;
constructor(props: Props) {
super(props)
}
public render() {
return <h1>home</h1>
}
}
Run Code Online (Sandbox Code Playgroud) 我在运行docker文件时收到docker的错误.它说的是/ var/lib/docker/aufs/layers/xxxx:当我运行Docker构建时没有这样的文件或目录.
我已经尝试了很多方法来删除容器和图像,所以我很喜欢这个.
任何
Docker文件是:
FROM node:6
RUN git clone https://github.com/preboot/angular2-webpack.git
WORKDIR angular2-webpack
RUN sed -i.bak 's/--port 8080/--host 0.0.0.0 --port 8080/'
package.json RUN npm i
CMD [ "npm", "run", "start" ]
Run Code Online (Sandbox Code Playgroud)
完整的控制台输出是:
Sending build context to Docker daemon
9.728 kB
Step 1 : FROM node:6
6: Pulling from library/node
6a5a5368e0c2: Already exists
7b9457ec39de: Already exists
ff18e19c2db4: Already exists
6a3d69edbe90: Already exists
0ce4b037e17f: Already exists
82252a100d5a: Already exists
Digest:
sha256:db245bde5445eb122d8dc090ba98539a9ef7f56c0ea981ade643695af0d8eaf0
Status: Downloaded newer image for node:6
---> 9873603dc506 Step 2 : …Run Code Online (Sandbox Code Playgroud) 我刚刚升级到"react-router":"^ 4.1.1",现在我从除默认路由之外的所有路由获得404.不确定我在这里缺少什么?
任何帮助表示赞赏.
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import Tee from './components/Tee'
import About from './components/About'
import Home from './components/Home'
class App extends Component {
render() {
return (
<BrowserRouter>
<div>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/tee" component={Tee} />
</Switch>
</div>
</BrowserRouter>
);
}
}
export default App;
ReactDOM.render((
<App />
),
document.getElementById('app')
);
Run Code Online (Sandbox Code Playgroud) 我在组件内部使用canvas对象来生成图表.为了它的动画,我正在递归地调用该方法.我一直收到错误,说明方法没有定义.不知道我需要如何构建它.
任何协助赞赏.
// Animate function
protected animate(draw_to) {
// Clear off the canvas
this.ctx.clearRect(0, 0, this.width, this.height);
// Start over
this.ctx.beginPath();
// arc(x, y, radius, startAngle, endAngle, anticlockwise)
// Re-draw from the very beginning each time so there isn't tiny line spaces between each section (the browser paint rendering will probably be smoother too)
this.ctx.arc(this.x, this.y, this.radius, this.start, draw_to, false);
// Draw
this.ctx.stroke();
// Increment percent
this.curr++;
// Animate until end
if (this.curr < this.finish + 1) {
// Recursive …Run Code Online (Sandbox Code Playgroud) 我升级了我的Web应用程序包,这次升级似乎打破了我的构建.我第一次收到错误告诉我安装webpack CLI,
CLI移动到一个单独的包中:webpack-cli.除了webpack本身之外,请安装'webpack-cli'以使用CLI.
- >使用npm时:npm install webpack-cli -D
- >使用纱线时:纱线添加webpack-cli -D module.js:471 throw err; ^
然后在得到上述错误并安装CLI后,我开始收到以下错误.它说有一个未知的属性加载器,但我传递的'加载器'数组如下:
module:{loaders:[[Object],[Object],[Object],[Object],[Object],[Object]]}}
配置对象无效.Webpack已使用与API架构不匹配的配置对象进行初始化. - configuration.module有一个未知的属性'loaders'.这些属性是有效的:object {exprContextCritical?,exprContextRecursive?,exprContextRegExp?,exprContextRequest?,noParse ?, rules?,defaultRules?,unknownContextCritical?,unknownContextRecursive?,unknownContextRegExp?,unknownContextRequest?,unsafeCache?,wrappedContextCritical?,wrappedContextRecursive?,wrappedContextRegExp ?,strictExportPresence?,strictThisContextOnImports?} - >影响正常模块的选项(
NormalModuleFactory).
- package.json
"url-loader": "^1.0.1",
"webpack": "^4.1.0",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.0"
Run Code Online (Sandbox Code Playgroud)
webpack共享配置
module.exports = {
entry: './src/main.js',
resolve: {
extensions: ['*', '.js', '.jsx']
},
module: {
loaders: [{
test: /\.jsx$|\.js$/,
loaders: ['babel-loader'],
include: path.resolve(__dirname, '../src')
},
{
test: /\.css$/,
loader: 'style-loader!css',
}, {
test: /\.woff2?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff',
include: path.resolve(__dirname, '../assets')
},
{
test: …Run Code Online (Sandbox Code Playgroud) 我有一个关于以下使用typescript数组的问题.这一切都很好但是当我通过linter运行时我得到以下错误,我的任务显然是错误的.
对于简单类型,禁止使用"Array"的数组类型.请改用'T []'.
export let data = [
{
"property": "value"
}
];
export interface myInterface {
property: string;
};
protected _collection: Array<myInterface>;
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
reactjs ×4
typescript ×4
node.js ×2
angular ×1
angularjs ×1
docker ×1
dockerfile ×1
javascript ×1
lambda ×1
react-router ×1
recursion ×1
unit-testing ×1
webpack ×1