2016-09-21 212 views
0

我做了所有的設置,包括在webstorm中添加typescript編譯器,安裝TSM與npm,和所有其他的東西。角度與typescript錯誤,找不到角度的名字

我仍然得到錯誤 '無法找到名稱角'

tsd.json

{ 

    "version": "v4", 
    "repo": "borisyankov/DefinitelyTyped", 
    "ref": "master", 
    "path": "typings", 
    "bundle": "typings/tsd.d.ts", 
    "installed": { 
    "angularjs/angular.d.ts": { 
     "commit": "70a693ec17c7ae4b9b7c1fa6c399ac3e82e3843e" 
    }, 
    "jquery/jquery.d.ts": { 
     "commit": "70a693ec17c7ae4b9b7c1fa6c399ac3e82e3843e" 
    } 
    } 
} 

sorting.html

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Title</title> 
</head> 
<body> 
{{$ctrl.mytest}} 
</body> 
</html> 

sorting.ts

var app = angular.module('myApp', []); 
app.component('sorting', { 
    templateUrl: 'modules/sorting/sorting.html', 
    controller: SortingClass 
}); 

class SortingClass { 

    public mytest: string = 'abcd'; 

} 

指數。 html

<!DOCTYPE html> 
<html> 
<head lang="en"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
    <meta charset="UTF-8"> 
    <title> Facility</title> 
    <script type="text/javascript" src="bower_components/angular/angular.js"></script> 
    <script src="modules/sorting/sorting.js" type="text/javascript"></script> 
</head> 
<body> 
</body> 
+0

的可能的複製[收到錯誤 - 無法找到名爲 '角'(https://開頭stackoverflow.com/questions/29915175/getting-error-cannot-find-name-angular) –

回答

-2

我的朋友,你有很多語法錯誤。請看看angular js的基礎知識。現在,試試這個代碼。這應該工作:

的Index.html

<!DOCTYPE html> 
<html ng-app="myApp"> 
<head lang="en"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
    <meta charset="UTF-8"> 
    <title> Facility</title> 
    <script type="text/javascript" src="bower_components/angular/angular.js"></script> 
    <script src="modules/sorting/sorting.js" type="text/javascript"></script> 
</head> 
<body ng-controller="sorting as ctrl"> 
    <div> {{ctrl.mytest}} </div> 
</body> 
</html> 

Sorting.ts

module xyz { 
var angular: any; 
var app = angular.module('myApp', []); 
app.controller('sorting', SortingClass); 

public class SortingClass { 
    public mytest: string = 'abcd'; 
} 
} 
+0

仍然不工作,我得到這個:{{$ ctrl.mytest}}在瀏覽器 – Zakk

+1

它不是$ ctrl。它只是ctrl。複製粘貼代碼並驗證它 –