在本文中,我们将带你了解如何在Angular2ngSwitch语句中使用typcript枚举值在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的Angular2ngSwitch不工作、ang
在本文中,我们将带你了解如何在Angular2 ngSwitch语句中使用typcript枚举值在这篇文章中,同时我们还将给您一些技巧,以帮助您实现更有效的Angular2 ngSwitch不工作、angular2 – 如何部署Angular 2应用程序开发的Typescript到生产?、angular2 – 我如何在angular 2中使用angular.copy、angularjs – angular-ui-router使用typescript嵌套命名视图。
本文目录一览:- 如何在Angular2 ngSwitch语句中使用typcript枚举值
- Angular2 ngSwitch不工作
- angular2 – 如何部署Angular 2应用程序开发的Typescript到生产?
- angular2 – 我如何在angular 2中使用angular.copy
- angularjs – angular-ui-router使用typescript嵌套命名视图
如何在Angular2 ngSwitch语句中使用typcript枚举值
请注意,这不同于如何基于枚举的所有值创建html选择选项(ngFor)。这个问题是关于ngSwitch基于枚举的特定值。虽然同样的方法创建一个类的内部引用枚举出现。
import {Component} from 'angular2/core'; enum CellType {Text,Placeholder} class Cell { constructor(public text: string,public type: CellType) {} } @Component({ selector: 'my-app',template: ` <div [ngSwitch]="cell.type"> <div *ngSwitchCase="cellType.Text"> {{cell.text}} </div> <div *ngSwitchCase="cellType.Placeholder"> Placeholder </div> </div> <button (click)="setType(cellType.Text)">Text</button> <button (click)="setType(cellType.Placeholder)">Placeholder</button> `,}) export default class AppComponent { // Store a reference to the enum cellType = CellType; public cell: Cell; constructor() { this.cell = new Cell("Hello",CellType.Text) } setType(type: CellType) { this.cell.type = type; } }
Angular2 ngSwitch不工作
我的html模板:
<!-- display closed date if status is closed,otherwise display active date --> <div ngSwitch="ACTV"> <divngSwitchWhen="CLSD"> <label for="closeDt"> Close Date <span>required field</span> </label> <div> <datetime [timepicker]="false" [(ngModel)]="date2" id="close-date" name="close-date"></datetime> </div> </div> <divngSwitchWhen="ACTV"> <label for="issueDt"> Active Date <span>required field</span> </label> <div> <datetime [timepicker]="false" [(ngModel)]="date2" id="active-date" name="active-date"></datetime> </div> </div> </div>
结果在npm服务器上:
解决方法
<div [ngSwitch]="someVariable"> <div *ngSwitchCase="value1">...</div> <div *ngSwitchCase="value2">...</div> </div>
angular2 – 如何部署Angular 2应用程序开发的Typescript到生产?
>在生产服务器中运行Angular 2应用程序的先决条件是什么?
>是否可能在IIS服务器中部署应用程序或需要节点服务器?
>在开发机器中使用节点编译文件后,我们需要将.js和.ts部署到生产环境吗?
<html> <head> <title>Hello Angular World</title> </head> <body> <div> <my-app>Loading...</my-app> </div> <script src="/js/myApp.bundle.min.js"></script> </body> </html>
这就是你需要的!
在将来,当HTTP / 2规范更常见时,可能不太需要捆绑基于模块的项目,但现在我认为需要捆绑。
没有对你的typescript文件的引用(因为它们已经在制作myApp.bundled.js的过程中被传递)。正如Zama所说,你可以在任何服务器上运行angular2(我使用IIS和工作正常)。
更新:自从Angular 2的最终版本,我已经切换到使用角度cli为建设生产。安装很容易(没有意大利面条的gulp任务),最后的包是超优化的(esp由于树摇晃)。我建议检查angular-cli设置,开发和构建您的ng2项目。
angular2 – 我如何在angular 2中使用angular.copy
使用angular 1我使用angular.copy(对象),但我得到一些错误使用角2。
EXCEPTION:ReferenceError:angular未定义
更新:
使用TypeScript 2.1,ES6简写对象扩展符号可用:
const copy = { ...original }
angularjs – angular-ui-router使用typescript嵌套命名视图
应用程序/ app.ts
module myModule{ class MyConfig { constructor( private $stateProvider:ng.ui.IStateProvider,private $urlRouterProvider:angular.ui.IUrlRouterProvider ) { this.init(); } private init():void { this.$stateProvider.state( 'home',{ abstract:true,template: '<main></main>',url: '/' }).state('home.main',{ views: { 'lhp@home': { template: '<lhp></lhp>' },'rhs@home': { template: '<rhs></rhs>' } },url: '/main',}); this.$urlRouterProvider.otherwise('/main'); } } let myApp = angular.module( 'myModule',['ui.router'] ); myApp.config(['$stateProvider','$urlRouterProvider',($stateProvider,$urlRouterProvider) => { return new MyConfig($stateProvider,$urlRouterProvider); }]);
}
main指令是一个简单的div,它是两个命名视图的容器
main.html中/ main.controller.ts
module app.Controllers { export class MainController { constructor( private $log:ng.ILogService ) { this.Init(); } private Init() { this.$log.info('Main Controller'); } } angular.module('myModule').controller( 'mainController',['$log',MainController] ); }
应用/组件/ main.html中
<div> <div id="wrap"> <div id="left_col" ui-view="lhp"></div> <div id="right_col" ui-view="rhs"></div> </div> </div>
应用/组件/ main.directive.ts
module app.Directives { 'use strict'; export class MainDirective implements ng.IDirective { public templateUrl:string = 'components/main.html'; public restrict:string = 'E'; public controller:string = 'mainController'; public scope = {}; constructor(private $log:ng.ILogService) { this.$log.info('main directive'); } public static Factory() { return (log:ng.ILogService) => { return new MainDirective(log); }; } } angular.module('myModule').directive('main',app.Directives.MainDirective.Factory()]); }
应用/组件/ lhp.controller.ts
module app.Controllers { export class LhpController { constructor( private $log:ng.ILogService ) { this.Init(); } private Init() { this.$log.info('LHP Controller'); } } angular.module('myModule').controller( 'lhpController',LhpController] ); }
应用/组件/ lhp.html
<div> THIS IS A TEST </div>
应用/组件/ lhp.directive.ts
module app.Directives { 'use strict'; export class LhpDirective implements ng.IDirective { public templateUrl:string = 'components/lhp.html'; public restrict:string = 'E'; public controller:string = 'lhpController'; public controllerAs:string = 'lctrl'; public scope = {}; constructor(private $log:ng.ILogService) { this.$log.info('lhp directive'); } public static Factory() { return (log:ng.ILogService) => { return new LhpDirective(log); }; } } angular.module('myModule').directive('lhp',app.Directives.LhpDirective.Factory()]); }
视图rhs的设置与lhp完全相同.我已经确认了两个rhs,并且lhp指令通过使home状态非抽象并将它们作为模板加载来正常工作.两者都正确呈现.当我做家庭状态摘要是我遇到问题.主控制器更不用说html根本不加载.打字稿和抽象视图有问题吗?有没有人遇到过类似问题和嵌套的命名视图?我在互联网上搜索了类似的例子,但找不到任何相关内容.我发现的最接近的例子是:How can I add ui-router stateProvider configuration to my application with Typescript?,它显示了一个抽象视图应该可以使用typescript,但是示例没有填写详细信息.我是否遗漏了嵌套命名视图的内容以使用typescript?
任何帮助将不胜感激.
解决方法
private init():void { this.$stateProvider.state( 'home',{ abstract:true,template: '<main></main>' }).state('home.main',{ views: { 'lhp@home': { template: '<lhp></lhp>' },'rhs@home': { template: '<rhs></rhs>' } },}); this.$urlRouterProvider.otherwise('/main'); }
今天关于如何在Angular2 ngSwitch语句中使用typcript枚举值的介绍到此结束,谢谢您的阅读,有关Angular2 ngSwitch不工作、angular2 – 如何部署Angular 2应用程序开发的Typescript到生产?、angular2 – 我如何在angular 2中使用angular.copy、angularjs – angular-ui-router使用typescript嵌套命名视图等更多相关知识的信息可以在本站进行查询。
本文标签: