拒绝从“*.ts”执行脚本,因为其 MIME 类型(“video/vnd.dlna.mpeg-tts”)不可执行

MAR*_*att 4 angularjs typescript

我是打字稿的新手。我有一个 angularjs 控制器,我正在尝试将其转换为 typescript 控制器。

首先我声明了控制器和模块

    /// <reference path='../../Scripts/typings/angularjs/angular.d.ts' />
/// <reference path='../../Scripts/typings/jquery/jquery.d.ts' />
'use strict'

interface IRouteParams extends ng.route.IRouteParamsService {
    propertyAddress: string;
}

class Controller1 {
    public propertyAdd: string;
    constructor($scope: any,
        $routeParams: IRouteParams,
        ServicesFactory,
        growl,
        blockUI,
        IMAGE_RELATED_MESSAGES,
        BUSY_MESSAGES,
        $timeout: ng.ITimeoutService,
        $modal,
        Lightbox,
        $filter) {

        this.propertyAdd = $routeParams.propertyAddress;

    }
}

angular.module('Controller').controller('Controller1', Controller1);
Run Code Online (Sandbox Code Playgroud)

当我在浏览器中运行此代码时,出现以下错误

拒绝执行来自“ http://localhost/....../Controller1.ts ”的脚本,因为它的 MIME 类型(“video/vnd.dlna.mpeg-tts”)不可执行。

痛点是什么?

sha*_*are 5

您必须将打字稿代码转换为常规的 javascript 代码。TypeScript 不应该直接在浏览器中运行。

使用tsc编译器来生成这样的 javascript:

tsc helloworld.ts
Run Code Online (Sandbox Code Playgroud)

更多详情请见官方网站