【问题标题】:Angularjs 2 typescript app permentaly movedAngularjs 2 typescript 应用程序永久移动
【发布时间】:2016-06-27 19:49:41
【问题描述】:

当我运行我的应用程序时,它给了我几个错误:

第一个是:

SyntaxError: class is a reserved identifier in the class thumbnail

代码:

const MAXHEIGHT = 170;
const MAXWIDTH = 320;
import {Subcategory} from './subcategory'
//import {Category} from './category'
import {bootstrap}    from 'angular2/platform/browser'

class Thumbnail {

    width: number;
    height: number;

    constructor(element: HTMLImageElement) {
        this.height = element.height;
        this.width = element.width;
    }

    resize(oImage: HTMLImageElement) {
        var maxWidth = 100; // Max width for the image
        var maxHeight = 100;    // Max height for the image
        var ratio = 0;  // Used for aspect ratio
        var width = oImage.width;    // Current image width
        var height = oImage.height;  // Current image height

        // Check if the current width is larger than the max
        if (oImage.width > MAXWIDTH) {
            ratio = MAXWIDTH / width;   // get ratio for scaling image
            oImage.width=MAXWIDTH; // Set new width
            oImage.height=height * ratio;  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }

        // Check if current height is larger than max
        if (height > MAXHEIGHT) {
            ratio = MAXHEIGHT / height; // get ratio for scaling image
            oImage.height= MAXHEIGHT;   // Set new height
            oImage.width= width * ratio;    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
            height = height * ratio;    // Reset height to match scaled image
        }
        // Check if current height is smaller than max
        if (height < MAXHEIGHT) {
            ratio = MAXHEIGHT / height; // get ratio for scaling image
            oImage.height = MAXHEIGHT;   // Set new height
            oImage.width = width * ratio;    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
            height = height * ratio;    // Reset height to match scaled image
        }
        // Check if the current width is smaller than the max
        if (oImage.width < MAXWIDTH) {
            ratio = MAXWIDTH / width;   // get ratio for scaling image
            oImage.width = MAXWIDTH; // Set new width
            oImage.height = height * ratio;  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
        document.body.appendChild(oImage);
        console.log(oImage.height);
        console.log(oImage.width);

    }

}; 

window.onload = () => {
    var oImage = new Image();
    var oImage2 = new Image();
    // var category = new Category(1, "string");
    var subcategory = new Subcategory("teste",1,2);
    oImage.src = 'AngularJS.png';
    oImage.setAttribute('class','img-responsive');
    oImage2.src = 'ts.jpg';
    var thumbnail = new Thumbnail(oImage);
    var thumbnail2 = new Thumbnail(oImage2);
    thumbnail.resize(oImage);
    thumbnail2.resize(oImage2);
    console.log(oImage.height);
    console.log(oImage.width);
};

第二个错误是:

获取http://localhost:51580/app

301 永久移动

angular的配置是:

 <script>
      System.config({
        packages: {
            TypeScriptHTMLApp1: {
            format: 'register',
            defaultExtension: 'js'
          }
        }
      });
      System.import('app')
            .then(null, console.error.bind(console));
    </script>

我已经尝试创建一个名为 app 的文件夹并移动了该文件夹的文件,但错误仍然存​​在。我需要帮助,我失去了几个小时,无法解决任何问题。我附上一张带有文件结构的图像,另一张带有萤火虫错误的图像。提前致谢。

【问题讨论】:

  • 尝试使用关键字作为类名前缀export
  • 给我同样的错误:SyntaxError: class is a reserved identifier class Thumbnail {
  • 你使用的是火狐?
  • 您在回答 cmets 中的 plnkr 确实是一团糟。我建议你从头开始。我已经使用class 让我的代码在以前版本的firefox 中工作,这意味着您的代码没有被转译,而是直接在浏览器中读取。按照教程进行操作,在一切正常之前不要从那里移动。

标签: javascript typescript angular


【解决方案1】:

正如@Eric 在评论中所建议的那样

根据this article,Firefox 版本

作为答案发布可能对某人有帮助。

【讨论】:

  • 在 chrome 中给我:Uncaught SyntaxError: Unexpected reserved word app.js:4 Uncaught TypeError: Cannot redefine property: onreadystatechange traceur-runtime.js:2 DEPRECATION WARNING: 'enqueueTask' is no longer support并将在下一个主要版本中删除。使用 addTask/addRepeatingTask/addMicroTask 弃用警告:“dequeueTask”不再受支持,将在下一个主要版本中删除。使用 removeTask/removeRepeatingTask/removeMicroTask 加载资源失败:服务器响应状态为 404 (Not Found)
  • 你能在任何 plunkr 上重新定义你的问题吗?这可能有助于我更好地理解您的问题。
  • 你在哪里引导你的主文件?似乎您的 plunkr 文件很少,不完整。
  • o需要导入bootsrap文件
  • 我在这个链接中找到了解决方案:stackoverflow.com/questions/30896227/…
猜你喜欢
  • 2018-06-18
  • 2017-09-04
  • 2019-11-04
  • 2017-07-04
  • 2012-07-10
  • 2018-05-24
  • 1970-01-01
  • 2017-08-02
  • 2016-11-04
相关资源
最近更新 更多