2016-09-21 117 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。复制粘贴代码并验证它 –