javascript – 如何使用TypeScript控制器和角度Js绑定数据

前端之家收集整理的这篇文章主要介绍了javascript – 如何使用TypeScript控制器和角度Js绑定数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@
我正在玩类型脚本.我已经将我的角度的js控制器转换为类型脚本,但我面临的问题在ng中继器. (我附上我的控制器代码如下: @H_403_2@class CustomCtrl{ public customer; public ticket; public services; public cust_File; public ticket_file; public service_file; static $inject = ['$scope','$http','$templateCache']; constructor ( private $http,private $templateCache ){}

解决方法

我决定添加另一个答案,介绍如何在TypeScript中创建和使用控制器,并将其注入到angularJS中.

这是这个答案的扩展

How can I define my controller using TypeScript?我们也有a working plunker

所以有这个指令:

@H_403_2@export class CustomerSearchDirective implements ng.IDirective { public restrict: string = "E"; public replace: boolean = true; public template: string = "<div>" + "<input ng-model=\"SearchedValue\" />" + "<button ng-click=\"Ctrl.Search()\" >Search</button>" + "<p> for searched value <b>{{SearchedValue}}</b> " + " we found: <i>{{FoundResult}}</i></p>" + "</div>"; public controller: string = 'CustomerSearchCtrl'; public controllerAs: string = 'Ctrl'; public scope = {}; }

我们可以看到,我们声明这个指令可以作为元素使用.我们也内衬了一个模板.此模板已准备好绑定SearchedValue并在我们的控制器Ctrl.Search()上调用Action.我们在说什么是控制器的名称:’CustomerSearchCtrl’,并要求运行时使其成为“Ctrl”(conrollerAs

猜你在找的JavaScript相关文章