0

enter image description here

When i run my application it gives me several errors:

the first one is:

SyntaxError: class is a reserved identifier in the class thumbnail

code:

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);
};

The second error is:

GET http://localhost:51580/app

301 Moved Permanently

The configuration of angular is:

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

I already tried to create a folder named app and moved the file for that folder but the error persists. I need help with this, I lost several hours and can't resolve anything. I attach one image with the file structure and another one with the firebug errors. Thanks in advance.

danday74
  • 52,471
  • 49
  • 232
  • 283
Fabio Santos
  • 253
  • 1
  • 4
  • 15

1 Answers1

0

as suggested by @Eric in comment

Classes aren't supported in Firefox version < 45 according to this article . instead try same use case in the chrome.

posted as answer may helpful to someone.

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
  • in the chrome give me : Uncaught SyntaxError: Unexpected reserved word app.js:4 Uncaught TypeError: Cannot redefine property: onreadystatechange traceur-runtime.js:2 DEPRECATION WARNING: 'enqueueTask' is no longer supported and will be removed in next major release. Use addTask/addRepeatingTask/addMicroTask DEPRECATION WARNING: 'dequeueTask' is no longer supported and will be removed in next major release. Use removeTask/removeRepeatingTask/removeMicroTask Failed to load resource: the server responded with a status of 404 (Not Found) – Fabio Santos Mar 12 '16 at 15:36
  • could you redefine your problem on any plunkr ? this may help me to understand your problem better. – Pardeep Jain Mar 12 '16 at 15:55
  • where you bootstrap your main file ? seems your plunkr is incomplete with few files. – Pardeep Jain Mar 12 '16 at 16:14
  • o need to import bootsrap file – Fabio Santos Mar 12 '16 at 16:19
  • why so ? how angular2 project can run without bootstarping ? strange – Pardeep Jain Mar 12 '16 at 16:19
  • how i import the file in plunkr? – Fabio Santos Mar 12 '16 at 16:21
  • simply create a new file and add to the existing plunkr/project and add it to the list of imports. – Pardeep Jain Mar 12 '16 at 16:22
  • haha @FabioSantos i mean to say angular2's `bootstrap` file where we bootstrap out main component or entry point for our app. seems you are new to angular2. the problem is your project did't found `app.js` file may be that's the reason your code is not working. – Pardeep Jain Mar 12 '16 at 16:28
  • yes, i'm try out angularjs 2. the file is in root diorectory, how i tell him that? – Fabio Santos Mar 12 '16 at 16:34
  • from your plunkr i have created one more plunkr for you which works fine. try using this plunkr to tell me the exact error you got and what you are trying to do. here is plunkr http://plnkr.co/edit/xEL1rITGKG7BAXgVwYIN?p=preview – Pardeep Jain Mar 12 '16 at 16:37
  • now i get this errors: GET http://localhost:51580/app 404 Not Found 2ms ReferenceError: require is not defined – Fabio Santos Mar 12 '16 at 16:39
  • import requirejs into index.html `https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.19/require.js` reuire is a module loader, also i have update my plunkr as per your needs check my plunkr. – Pardeep Jain Mar 12 '16 at 16:42
  • I am using visual studio 201 for web and get the error:Severity Code Description Project File Line Suppression State Error Build: Class 'AppComponent' incorrectly implements interface 'OnInit'. TypeScriptHTMLApp1 D:\TypeScriptHTMLApp1\TypeScriptHTMLApp1\app\app.component.ts 12 in the line export class AppComponent implements OnInit – Fabio Santos Mar 12 '16 at 16:48
  • import `OnInit` before using OnInit method see my plnkr for usage of OnInit – Pardeep Jain Mar 12 '16 at 16:50
  • i do copy paste from your plunkr – Fabio Santos Mar 12 '16 at 16:52
  • than try removing OnInit. in my system this works witout ny error – Pardeep Jain Mar 12 '16 at 16:55
  • i remove and get this error : Severity Code Description Project File Line Suppression State Error Build: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. TypeScriptHTMLApp1 – Fabio Santos Mar 12 '16 at 17:02
  • please first clear yourself whats the errors you got then either ask a new question or edit and update the same question. as of comments m too confused with your errors sorry. – Pardeep Jain Mar 12 '16 at 17:04
  • 1
    i found the solution in this link:http://stackoverflow.com/questions/30896227/visual-studio-2015-rc-typescript-experimental-decorators-error – Fabio Santos Mar 12 '16 at 17:24