0

我正在使用 typescript 创建一个非常简单的 Web 应用程序。现在,它所要做的就是创建一个矩形并显示该区域的信息吐司。不幸的是,吐司从未出现。该代码行已执行,并且在 Internet Explorer 或 Google Chrome 的开发工具中没有错误或警告。这是我所拥有的:

打字稿:

/// <reference path="../typings/toastr/toastr.d.ts" />
interface IRectangle {
   height: number;
   width: number;
   getArea(): number;
}

module Shapes {
   export class Rectangle implements IRectangle {
      getArea(): number {
         return this.height * this.width;
      }

      constructor(
         public height: number,
         public width: number) {

      }
   }
}

var rect: IRectangle = new Shapes.Rectangle(10, 4);
var area = rect.getArea();
toastr.info("area = " + area);

生成的javascript如下:

/// <reference path="../typings/toastr/toastr.d.ts" />
var Shapes;
(function (Shapes) {
    var Rectangle = (function () {
        function Rectangle(height, width) {
            this.height = height;
            this.width = width;
        }
        Rectangle.prototype.getArea = function () {
            return this.height * this.width;
        };
        return Rectangle;
    })();
    Shapes.Rectangle = Rectangle;
})(Shapes || (Shapes = {}));
var rect = new Shapes.Rectangle(10, 4);
var area = rect.getArea();
toastr.info("area = " + area);
//# sourceMappingURL=04-01-internal-module.js.ma

我的 HTML 仅用于显示吐司。这是一个简单的例子,我可以想象,但它仍然不起作用:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/jquery-1.6.3.js"></script>
    <link href="../content/toastr.css" rel="stylesheet" />
    <script src="../scripts/toastr.js"></script>
    <script src="../scripts/app/04-02-internal-module.js"></script>
</head>
<body>

</body>
</html>

就像我说的。页面加载得很好,但没有任何反应。我知道我应该看到什么,因为我使用了位于此处的演示: http: //codeseven.github.io/toastr/demo.html

但是,什么也没有出现。任何想法我做错了什么?

4

1 回答 1

2

我创建了一个小提琴,它似乎工作正常,我唯一可以建议的是你的文件还没有准备好,所以试着像这样包装

$(document).ready(function () {
  toastr.success("message", 'test');
});

工作小提琴

于 2015-09-03T19:14:47.313 回答