有条码错误的角度,找不到名字的角度

时间:2016-09-21 11:52:53

标签: angularjs typescript

我完成了所有设置,包括在webstorm中添加typescript编译器,使用npm安装tsd以及所有其他内容。

我仍然收到错误'找不到名字Angular'

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';

}

的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>

1 个答案:

答案 0 :(得分:-2)

我的朋友,你有很多语法错误。请查看角度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';
 }
}