此处将为大家介绍关于TypeScript2.0与AngularJS2.0的最新动态的详细内容,并且为您解答有关typescript和angular的相关问题,此外,我们还将为您介绍关于angular–
此处将为大家介绍关于TypeScript 2.0 与 AngularJS 2.0 的最新动态的详细内容,并且为您解答有关typescript和angular的相关问题,此外,我们还将为您介绍关于angular – 由typescript导入的代码的Typescript类型?、AngularJS 2 – 使用哪种语言? (Typescript,Javascript,Dart)、AngularJS TypeScript指令链接功能、AngularJS ui路由器是否有任何Typescript定义?的有用信息。
本文目录一览:- TypeScript 2.0 与 AngularJS 2.0 的最新动态(typescript和angular)
- angular – 由typescript导入的代码的Typescript类型?
- AngularJS 2 – 使用哪种语言? (Typescript,Javascript,Dart)
- AngularJS TypeScript指令链接功能
- AngularJS ui路由器是否有任何Typescript定义?
TypeScript 2.0 与 AngularJS 2.0 的最新动态(typescript和angular)
Lightbot微软终于发布了 TypeScript 2.0 的第一个 RC 版本。TypeScript 是一个简化版的 JavaScript 语言,被大量用于各种 Web 项目,包括下面提到的著名的 AngularJS 框架。 |
TypeScript 2.0 中主要的特性是“标签结合”,这个特性可以将两个不同的数据结构联合到一起。你可以把它想象成将一个圆圈和一个方块放一起,这个隐喻来自微软解释标签结合的博文中。
支持标签结合的语言包括 C++、 Scala、 F#、Rust 和 Swift 等等。支持这种特性的原因是,标签结合可以改进类型安全,并减少经常困扰开发者的类型错误。
而另外一方面,Google 也有一些动作……
Google 已经谈论 AngularJS 2.0 很久了。很多人都期望 Google 能在去年底发布 2.0 的稳定版,不过我们听说,就算是到了今年年底也不会见到稳定版。
不过,也快了!Google 今天宣布发布了 Angular 2.0 RC6,支持国际化(I18N)、更多的表单功能,并由于对 Ahead of Time (AoT) 的兼容和支持 ES6 2015 模块而改进了性能。
同时 Google 也宣布发布了 Angular Material 1.1,这是一个 AngularJS 的 UI 组件包。Angular Material 2.x 当前还处于 alpha 阶段,看起来会在 AngularJS 2.0 发布之后才会面世。当前,Angular Material 2.x 已经从 6 个组件增加到了 18 个组件了。
angular – 由typescript导入的代码的Typescript类型?
我正在开发一个Angular 7应用程序,我正在使用一些库,这些库是通过前端的脚本标签从其他来源(Stripe,recaptcha,googletags等)导入的.我将在这里使用Stripe作为示例,因为Stripe绝对要求客户端从Stripe.js导入前端库以实现PCI兼容性,因此从源服务器端不是一个选项.
我已经从DefinitelyTyped安装了Stripe的类型.如果我添加声明让Stripe:any;并且在组件中使用Stripe,它可以工作,但当然它不是类型安全的.如果我省略声明,VSCode发现类型很好,编辑器捕获类型错误,但它不会编译,(错误TS2304:找不到名称’Stripe’.)可能因为我没有Stripe的import语句.
有没有办法提示TypeScript它应该使用DefinitelyTyped中的类型来捕获类型错误,而不导入Stripe库本身?
编辑:我收回我所说的关于不认为这是Angular特定的内容.我现在认为这可能与角度编译过程有关.
解决方法
所以,我所做的是,我将Type DeFinition文件(通常是index.d.ts)复制到我的代码库中.
之后,您可以执行以下操作:
import {SomeType} from "sometype.d.ts" declare let ObjectImportedFromHTMLScriptTag: SomeType;
然后,您可以使用导入的对象而不会破坏类型安全性.
AngularJS 2 – 使用哪种语言? (Typescript,Javascript,Dart)
打字稿,Javascript和飞镖。
我只习惯了Javascript EcmaScript 5,我想知道这三个的强度和弱点是什么?
在问这个问题的时候,文档是更加发达的Typescript和漂亮的苗条其他人(甚至他们自己的语言Dart):
> Typescript:4教程,16开发人员指南,4测试指南
> Javascript:0教程,4开发人员指南,0测试指南
> Dart:0教程,14开发人员指南,0测试指南
我应该改变我的开发使用Javascript的习惯,并遵循Angular 2使用Typescript建议的习惯?它真的改变了Javascript的概念吗?
AngularJS 2.0官网
TypeScript
对于TS,有最多的资源(文档,…),因为有一个巨大的用户群。
Dart和JS版本的Angular是从TS生成的。
似乎有很多问题,以获得一个Angular TS项目启动和运行(见Angular2问题在这里SO),但有种子项目可用,一切已经建立。我不知道细节,因为我只使用Dart自己。
对于TS现在有Angular CLI,它改善了Angular2的TypeScript的开发者体验。
JavaScript,ES5,ES6
如果你是一个JS纯粹主义者,它可能是你正确的语言。如果没有(如果你是你可能不会问这个问题),那么我相信你最好使用Dart或TS。
Angular使用类型注释在几个方面。使用JS需要“解决方法”,否则一个简单的类型注释就足够了(主要是依赖注入)。
镖
Dart是一个很好的语言与一组工具,一起工作良好。
很多问题的JS / TS环境导致Dart解决优雅。
自从2016/05年左右Angular2 Dart是一个独立的项目,与TS和JS版本(截至2016/10)有很大不同。
>在TS中多次替换的路由器模块使其与离线模板编译工作,在Dart中没有被替换,因为在Dart延迟加载也可以与“老”路由器正常工作。> …而且NgModule也没有介绍给Dart因为同样的原因。>为TS创建的新的Forms模块未移植到Dart。> Dart从一开始就有离线模板编译,但不支持browser-platform-dynamic在运行时编译组件。>一个新的依赖注入模块似乎正在进行中的Dart基于Dagger2(目前还不可用)替换自动生成的TypeScript代码的DI系统。> Angular2 Dart强烈关注构建输出大小和运行时性能,但是AFAIK支持多平台支持(如服务器端渲染)已被放弃。
AngularJS TypeScript指令链接功能
我的主要问题是我的服务无法在我的链接功能中使用.
以下是我要实现的一个例子:
module app.directives { export var directiveName: string = "theDirective"; angular.module("myApp").directive(directiveName,(myFactory: app.services.MyFactory) => { return new MyDirective(myFactory); }); export interface IMyDirectiveScope extends ng.IScope { ngModel: ng.INgModelController; } export class MyDirective implements ng.IDirective { restrict = "A"; require = "ngModel"; scope = { ngModel:'=' } constructor(private myFactory: app.services.MyFactory) { } link(scope: IMyDirectiveScope,elem: JQuery,attributes: ng.IAttributes,ngModel: ng.INgModelController) { //this is window here elem.bind('blur',(evt: JQueryEventObject) => { //keyword this is also window here,so yeah bummer indeed validate(); }); function validate() { //I need to use my factory here,but I can seem to get it. //this is always window and I'm kinda stuck here } } } }
我似乎找不到一些更高级的东西在这个话题.所有的示例我都没有发现似乎不使用服务或复杂的链接功能.
请以某种方式回答这个问题.这是你想的诡计.
更新:我的链接函数内的“this”是窗口而不是“MyDirective”对我来说没有什么意义.任何想法为什么会这样?
export class MyDirective implements ng.IDirective { public link; restrict = "A"; require = "ngModel"; scope = { ngModel:'=' } constructor(private myFactory: app.services.MyFactory) { this.link = this.unboundLink.bind(this); } unboundLink(scope: IMyDirectiveScope,ngModel: ng.INgModelController) { //Now you should be able to access myFactory this.myFactory.doSomething(); elem.bind('blur',(evt: JQueryEventObject) => { //keyword this is also window here,so yeah bummer indeed validate(); }); function validate() { //I need to use my factory here,but I can seem to get it. //this is always window and I'm kinda stuck here } } }
编辑:没有类,你可以这样做:
angular.module("myApp").directive("theDirective",function(myFactory: app.services.MyFactory) { return { restrict: 'A',require: 'ngModel',scope: {'ngModel': '='},link: function(scope: IMyDirectiveScope,ngModel: ng.INgModelController) { //You can access myFactory like this. myFactory.doSomething(); } } } );
AngularJS ui路由器是否有任何Typescript定义?
我在ui-router中使用Typescript。有没有人为此找到任何打字稿定义。我看了确定的打字,什么也看不见。这是我要查找的接口文件:
$stateProvider
答案1
小编典典我们将此 d.ts 用于ui-router
:
更新的链接,2015年5月
https://github.com/borisyankov/DefinitelyTyped/blob/master/angular-ui-
router/angular-ui-
router.d.ts
原始版本 (准备复制/粘贴)
https://raw.githubusercontent.com/borisyankov/DefinitelyTyped/master/angular-
ui-router/angular-ui-
router.d.ts
升级说明:
当我更新angular-ui-router.d.ts
到最新版本(2015年5月)时,我还遇到了一些构建问题。简而言之,解决方案是
- 角度定义已转换
- 从:
declare module ng {
- 变成:
declare module angular {
- 所以更新
angular.d.ts
到最新版本- 更新所有相关的 (现有的)
d.ts
,以及 (角animate.d.ts,角sanitize.d.ts …)- 更改所有其他
(custom)
模块声明,例如
declare module ng.XXX {
进入declare module angular.XXX {
通过以下几个步骤,所有步骤都应重新工作 (
原始的,而不是有效的链接)
该资源的小代码段形式:
// Type definitions for Angular JS 1.1.5+ (ui.router module)// Project: https://github.com/angular-ui/ui-router// Definitions by: Michel Salib <https://github.com/michelsalib>// Definitions: https://github.com/borisyankov/DefinitelyTyped/// <reference path="../angularjs/angular.d.ts" />declare module ng.ui { interface IState { ...
用法示例
module MyModule{ export class MyStateConfig { constructor(private $stateProvider: ng.ui.IStateProvider , private $urlRouterProvider: ng.ui.IUrlRouterProvider ...) { this.$stateProvider.state(...
关于TypeScript 2.0 与 AngularJS 2.0 的最新动态和typescript和angular的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于angular – 由typescript导入的代码的Typescript类型?、AngularJS 2 – 使用哪种语言? (Typescript,Javascript,Dart)、AngularJS TypeScript指令链接功能、AngularJS ui路由器是否有任何Typescript定义?的相关知识,请在本站寻找。
本文标签: