Tag: 打字稿

在Angular2应用程序中使用Chartjs

我目前正在和TypeScript一起探索Angular2,我想在我的应用程序中包含Chartjs模块。 在chartjs文档中显示了如何使用通用的canvas HTML标签来完成它: <canvas id="myChart" width="400" height="400"></canvas> <script> var ctx = document.getElementById("myChart"); var myChart = new Chart(ctx, {[…]}); </script> 我怎样才能用Angular2和TypeScript做类似的事情? 提前致谢!

使用模块的Typescript

我正在尝试构build我的第一个简单的基于ORM的Node JS应用程序。 我创build了这样的Database模块 import * as Knex from 'knex'; import * as Bookshelf from 'bookshelf'; module Database { class Config { private static _knex: Knex = Knex({ client: 'mysql', connection: { host: '127.0.0.1', user: 'root', password: '', database: 'test', charset: 'utf8' } }); static _bookshelf: Bookshelf = Bookshelf(Config._knex); } export function bookshelf() { Config._bookshelf.plugin('registry'); Config._bookshelf.plugin(['virtuals']); […]

types安装不适用于已configuration的打字稿定义

我有typings.json文件与声明,包括我的项目所需的一些打字稿定义。 检查下面的参考 … "ambientDependencies": { "bluebird": "registry:dt/bluebird#2.0.0+20160319051630", "express": "registry:dt/express#4.0.0+20160317120654", "express-serve-static-core": "registry:dt/express-serve-static-core#0.0.0+20160322035842", … 但是当我尝试执行typestypings install命令没有得到安装和打字稿下面的语句 — (No dependencies) 与npm install package.json软件包的npm install不同,typings命令不能按预期工作。 我有一个错误的假设? 到目前为止,我已经避免了在版本控制(如node_modules )中检查打字稿定义(存储在打字文件夹内)。 是否有必要签入这个文件? 更新这是我的错误,我更新typings命令行实用程序版本1.0.5 。 我检查了https://github.com/typings/typings,并意识到我需要改变typings.json来使用新的主要版本。 改变了typings.json按照网站上给出的指示,现在正在工作。

如何更新Angular 2和Node JS中的ng2-chartjs2图表中的数据

我正在使用NodeJS,Angular2和ng2-chartjs2。 下面我列出了我的代码渲染图表的相关部分。 数据从使用固定date范围的API加载到this.data中。 我想让用户select一个date范围,然后更新图表。 从这里我知道你可以调用图表对象的update()来更新数据,但是我不知道如何获取图表对象,因为组件代码实际上并没有引用它 -当模板被渲染时,它是自动完成的。 查看源代码 (第13行),我看到作者打算让对象可用。 我联系了作者,但还没有收到答复,需要搬家。 我已经学到了很多关于Angular2的知识,但是我还没有专家,所以对Angular2的更深入的理解使得这一点变得很明显。 我怎样才能访问对象来调用它的update(),或者做一些其他干净的方式? 该模板包含 <chart [options]="simple.options"></chart> 和组件打印脚本代码包含 import { ChartComponent } from 'ng2-chartjs2'; … @Component({ selector: 'home', templateUrl: 'client/components/home/home.component.html', styleUrls: ['client/components/home/home.component.css'], directives: [DashboardLayoutComponent, CORE_DIRECTIVES, ChartComponent], pipes: [AddCommasPipe], }) … setCurrentSimpleChart = (simpleType: number): void => { this.simple.options = { type: 'line', options: this.globalOptions, data: { labels: this.data[simpleType].labels, […]

如何从承诺中的事件处理程序返回值?

我正在构build一个使用nodegit npm包的nodeJS应用程序。 所以根据他们的文档中的例子,我有以下章节。 它使用了一系列的promise,看起来像一个JQuery事件处理程序。 这是我的function: export function prepareDiffs() { var patt = new RegExp('[0-9].[0-9]'); var results: Array<Commit> = []; Git.Repository.open("features/tutorial") // Open the repository directory. .then(function (repo) { // Open the master branch. return repo.getMasterCommit(); }) .then(function (firstCommitOnMaster) { // Display information about commits on master. var history = firstCommitOnMaster.history(); // Create a new history […]

在使用Typescript的Aurelia中使用Jquery

我使用Aurelia与打字稿,使用aurelia-cli和npm作为构build系统和客户端包pipe理器。 我的目标是在我的一个.ts文件中使用jquery,所以我添加了jquery npm install jquery@2.2.4 –save 之后用于types我使用: typings install dt~jquery –global –save 我还configuration了“jquery”作为供应商捆绑依赖的aurelia.json文件。 使用: import * as jq from 'jquery'; 但该项目未能build立以下错误: Starting 'readProjectConfiguration'… Finished 'readProjectConfiguration' Starting 'processMarkup'… Starting 'processCSS'… Starting 'configureEnvironment'… Finished 'processCSS' Finished 'processMarkup' Finished 'configureEnvironment' Starting 'buildTypeScript'… typings/globals/jquery/index.d.ts(3218,13): error TS2403: Subsequent variable declarations must have the same type. Variable '$' must be of […]

Typescript – > ES5问题

我在打字稿中写这个: const mask = […Array(10)].map((item) => 0); 在节点控制台中,它生成一个10个零的数组: > […Array(10)].map((item) => 0); [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] 一旦在javascript中传输,它会产生: var mask = Array(10).slice().map(function (item) { return 0; }); 但是这不是等同的: > Array(10).slice().map(function (item) { return 0; }) [ , , , , , , , , , ] 我的印象是打字稿应该产生isofunction的代码。 我错了吗? […]

Typescript版本不更新

我正在运行以下命令将我的TypeScript版本从1.8.5更新到2.0.7: npm安装-g打字稿 它显示为– typescript@2.0.7 之后,当我尝试使用: tsc –version手动检查它时,它显示了我: 版本1.8.5 请告诉我如何将版本从版本1.8.5升级到版本2.0.7 。

如何将userId从浏览器传递给量angular器?

所以我已经在我的angular2组件中使用* ngFor来呈现用户。 <ul> <li *ng-for="let user of users"> <input [(ng-model)]="user.name"> <button (click)="remove(user._id)">Remove</button> <a [routerLink]="['/edit',user._id]"> <i class="fa fa-eye fa-fw"></i> </a> </li> </ul> 现在在我的量angular器testing中,当我点击这个链接时,不导航到编辑组件。 所以我想要做的是: 通过传递任何user._id导航到editComponent,但我不知道如何将user._id从模板传递给量angular器e2etesting。 以下是我的testing: it('should redirect to edit', () => { browser.get('/edit/'+user._id); //here I want to pass user._id which is inside *ngFor of browser browser.waitForAngular(); }); 任何方式来做到这一点? 谢谢

错误TS7027:在Angular2 TypeScript Service类中检测到无法访问的代码

我正在跟着一个PluralSight课程,并在Angular2中练习写一个基本的服务。 我有以下服务文件: customer.service.ts import { Injectable } from '@angular/core'; @Injectable() export class CustomerService { constructor() {} getCustomers() { return [ {id: 1, name: 'Ward'}, {id: 2, name: 'Joe'}, {id: 3, name: 'Bill'}, {id: 4, name: 'Bob'}, {id: 5, name: 'Levi'}, {id: 6, name: 'Brian'}, {id: 7, name: 'Susie'} ]; } } 当我使用npm start lite-server npm […]