简体   繁体   English

带有打字稿错误的角度,找不到名称角度

[英]angular with typescript error, cannot find name angular

I done all the settings including adding typescript compiler in webstorm, installing tsd with npm, and all other stuff. 我完成了所有设置,包括在webstorm中添加Typescript编译器,使用npm安装tsd以及所有其他内容。

I still get error 'Cannot find name Angular' 我仍然收到错误消息“找不到名称Angular”

tsd.json 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 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';

}

index.html index.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>

My friend, you have lot of syntax errors. 我的朋友,您有很多语法错误。 Please have a look at the basics of angular js. 请看一下angular js的基础知识。 For now, try this code. 现在,尝试此代码。 This should work: 这应该工作:

Index.html 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';
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM