녹아웃 바인딩이 마크 업에서 선언되는 방식에 대해서는 아무것도 바뀌지 않지만 녹아웃 라이브러리에 대한 인터페이스가 작성되면 인텔리전스를 얻을 수 있습니다. 이와 관련하여 대부분의 jQuery API에 대한 인터페이스를 포함 하는 typescript 파일 이있는 jquery Sample 과 동일하게 작동 합니다.
ko와 $에 대한 두 개의 변수 선언을 제거하면 코드가 작동한다고 생각합니다. 이들은 knockout 및 jquery 스크립트가로드 될 때 생성 된 실제 ko 및 $ 변수를 숨기고 있습니다.
Visual Studio 템플릿 프로젝트를 녹아웃하기 위해이 작업을 수행해야했습니다.
app.ts :
class GreeterViewModel {
timerToken: number;
utcTime: any;
constructor (ko: any) {
this.utcTime = ko.observable(new Date().toUTCString());
this.start();
}
start() {
this.timerToken = setInterval(() => this.utcTime(new Date().toUTCString()), 500);
}
}
window.onload = () => {
// get a ref to the ko global
var w: any;
w = window;
var myKO: any;
myKO = w.ko;
var el = document.getElementById('content');
myKO.applyBindings(new GreeterViewModel(myKO), el);
};
default.htm :
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>TypeScript HTML App</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script src="Scripts/knockout-2.1.0.debug.js" type="text/javascript"></script>
<script src="app.js"></script>
</head>
<body>
<h1>TypeScript HTML App</h1>
<div id="content" data-bind="text: utcTime" />
</body>
</html>