我正在玩类型脚本.我已经将我的角度的js控制器转换为类型脚本,但我面临的问题在ng中继器. (我附上我的控制器代码如下:
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
所以有这个指令:
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
总结
以上是DEVMAX为你收集整理的javascript – 如何使用TypeScript控制器和角度Js绑定数据全部内容。
如果觉得DEVMAX网站内容还不错,欢迎将DEVMAX网站推荐给好友。