GVKun编程网logo

在IE中调试角度2的打字稿应用程序

10

在这篇文章中,我们将带领您了解在IE中调试角度2的打字稿应用程序的全貌,同时,我们还将为您介绍有关anglejs–需要(多)角度的打字稿、angularjs–$scope的提供者!在角度2应用程序中使

在这篇文章中,我们将带领您了解在IE中调试角度2的打字稿应用程序的全貌,同时,我们还将为您介绍有关anglejs – 需要(多)角度的打字稿、angularjs – $scope的提供者!在角度2应用程序中使用角度1指令时出错、angularjs – 如何配置Angular2应用程序使用Maven的打字稿?、asp.net-mvc – 使用.net mvc在IIS角度2应用程序上发布的知识,以帮助您更好地理解这个主题。

本文目录一览:

在IE中调试角度2的打字稿应用程序

在IE中调试角度2的打字稿应用程序

我可以在Chrome和Firefox中轻松调试我的角度2(角度cli生成的项目)Typescript文件,但我无法在IE 11中调试我的任何打字稿文件.我在列表中看到的所有文件都是.js类型可以任何一个指南我,我做错了或如何在IE中调试应用程序.
在IE 11中,您需要在“Dynamic Sc​​ripts”下找到的调试器中打开.ts文件.

向下滚动并找到.ts文件并在调试中打开它.

anglejs – 需要(多)角度的打字稿

anglejs – 需要(多)角度的打字稿

我似乎已经打了墙,我无法分解.我正在使用角度的脚本,并希望使它与requirejs一起工作.定义了多个角度应用程序,这些应用程序根据正文的数据应用程序名称属性进行加载.

文件夹结构(简体):

@H_301_3@|- Libs |- angular |- some-plugin |- angular-some-plugin // Exposes an angular.module("ngSomePlugin") |- require.js |- Common |- Common.ts // Exposes an angular.module("common") |- App1 |- Controllers |- SomeController.ts |- SomeOtherController.ts |- Services |- SomeService.ts |- Main.ts |- App.ts |- App2 // same as above |- Appx // same as above |- Index.html |- Main.ts

内容:

index.html的:

@H_301_3@// All these attributes are set dynamically server-side <body id="ng-app-wrapper" data-directory="App1" data-app-name="MyApp"> <script src="Libs/require.js" data-main="Main"></script> </body>

Main.ts:

@H_301_3@console.log("Step 1: Main.js"); requirejs.config({ paths: { "angular": "Libs/angular/angular","common": "Common/common" },shim: { "angular": { exports: "angular" } } }); require(["angular"],(angular: angular.IAngularstatic) => { angular.element(document).ready(function() { var $app = angular.element(document.getElementById("ng-app-wrapper")); var directory = $app.data("directory"); var appName = $app.data("app-name"); requirejs.config({ paths: { "appMain": directory + "/Main" } }); require([ 'common','appMain' ],function () { console.log("Step 5: App1/Main.js loaded"); console.log("Step 6: Bootstrapping app: " + appName); angular.bootstrap($app,[appName]); }); }); });

App1中的Main.ts

@H_301_3@console.log("Step 2: App1/Main.js"); requirejs.config({ paths: { "app": "App1/App","somePlugin": "Libs/some-plugin/some-plugin",// This is an AMD module "ngSomePlugin": "Libs/angular-some-plugin/angular-some-plugin" },shim: { "ngSomePlugin": { exports: "ngSomePlugin",deps: ["somePlugin"] } } }); define([ "app" ],() => { console.log("Step 4: App.js loaded"); });

应用1 / App.ts:

@H_301_3@console.log("Step 3: App.js"); import SomeController = require("App1/Controllers/SomeController"); import SomeOtherController = require("App1/Controllers/SomeOtherController"); import SomeService = require("App1/Services/SomeService"); define([ "angular","ngSomePlugin" ],(angular: angular.IAngularstatic) => { // This isn't called,so obvIoUsly executed to late console.log("Defining angular module MyApp"); angular.module("MyApp",["common","ngSomePlugin"]) .controller("someCtrl",SomeController.someController) .controller("someOtherCtrl",SomeOtherController.someOtherController) .service("someService",SomeService.someService) ; });

这似乎打破了,与旧的错误:
未捕获错误:[$inject:nomod]模块’MyApp’不可用!您拼错了模块名称或忘记加载它.

问题1:

我在这里做错了什么?在我引导我的应用程序之前,如何确保angular.module()调用完成?

这是console.logs的输出,在那里你可以看到角度还没有定义模块angular.module(“MyApp”),所以这样做明显晚了:

UPDATE
我可以在App.ts中打开角度调用,所以它不需要任何东西(除了顶部的导入).然后如果我将App添加到App1 / Main.ts中的垫片,并在其中放置依赖关系似乎有效.这是解决这个问题的好方法吗?

UPDATE2
如果我在App.ts中使用require而不是define,它会实例化角度模块,但是在它尝试引导它之后.

问题2:

有没有办法传递自定义配置,例如Libs的目录名称?我尝试了以下似乎不起作用(Main.ts):

@H_301_3@requirejs.config({ paths: { "appMain": directory + "/Main" },config: { "appMain": { libsPath: "Libs/" },"app": { name: appName } } });

应用1 / Main.ts:

@H_301_3@define(["module"],(module) => { var libsPath = module.config().libsPath; requirejs.config({ paths: { "somePlugin": libsPath + "somePlugin/somePlugin" // rest of paths } }); define([ // or require([]) "app" ],() => {}); });

App.ts:

@H_301_3@define([ "module" // others ],(module) => { angular.module(module.config().name,[]); });

但是在逻辑上,这种方式,angular.bootstrap()并不等待加载App.ts.因此角度模块尚未定义,并且无法引导.看来你不能像App1 / Main.ts那样做一个嵌套的定义?我该如何配置?

问题1

亚历山大·贝雷斯基(Alexander Beletsky)写了一篇关于将requireJS和Angular联系在一起的great article(以及为什么它值得的).在其中,我想他有你的第一个问题的答案:从另一个模块加载角度,然后进行自举呼叫.这迫使需要JS在执行任何代码之前加载这些模块的依赖关系.

假设这是你的主要

@H_301_3@console.log("Step 1: Main.js"); requirejs.config({ paths: { "angular": "Libs/angular/angular","common": "Common/common". "mainT1": "t1/main.js" },shim: { "angular": { exports: "angular" } } });

在最后添加一个调用您的下一个模块

@H_301_3@requirejs(["app"],function(app) { app.init(); });

在t1的主要内容中,您可以使实际的应用程序一次性加载.

T1 / main.ts

@H_301_3@define("app-name",['angular'],function(angular){ var loader = {}; loader.load = function(){ var app = angular.module("app-name",[]); return app; } return loader; }

最后,我们假设你在这里提供了一个临时文件,它带有你的app.js.在这里,您可以设置顺序来获取已经完成角度加载序列的对象.一旦完成,那么你在init()函数中调用bootstrapping.

T1 / app.js

@H_301_3@define("app",function(require){ var angular = require('angular'); var appLoader = require('mainT1'); var app = {} app.init = function(){ var loader = new appLoader(); loader.load(); angular.bootstrap(document,["app-name"]); } }

angularjs – $scope的提供者!在角度2应用程序中使用角度1指令时出错

angularjs – $scope的提供者!在角度2应用程序中使用角度1指令时出错

我有一个使用angular-cli构建的角度2应用程序,我需要在我的一个组件中使用角度1指令(从不同的应用程序重用它).我按照以下步骤操作:

https://angular.io/docs/ts/latest/guide/upgrade.html#!#using-angular-1-component-directives-from-angular-2-code

但现在我遇到了这个错误,无法超越它.我正在使用angular2.0.2(我设法在过去使用beta版本构建了一个混合应用程序,但它是一个angular1应用程序,我使用角度2组件与适配器的降级功能).

在我的app.module.ts中我有:

import { UpgradeAdapter } from '@angular/upgrade';
const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));

const HeroDetail = upgradeAdapter.upgradeNg1Component('heroDetail');

@NgModule({
    imports:      [
        browserModule,...
    ],declarations: [
      ...       
     HeroDetail
     ]
})
export class AppModule { }

我的hero-detail.component.ts看起来像这样:

export const heroDetail = {
  templateUrl: 'hero-detail.html',controller: function() {
  }
};

而我的hero-detail.html看起来像这样:

<h2>Windstorm details!</h2>

我只是通过添加模板尝试在另一个角度2组件中使用该指令:

当我运行服务时,应用程序编译正常,但当我尝试加载页面时,我得到上述错误.

关于如何向前推进的任何建议?

解决方法

看来你的引导逻辑不正确.

它实际上不是很明显,请确保:

>你不用@NgModule({bootstrap:[…]})引导任何ng2组件.相反,您应该在主模块中使用空的ngdobootstrap(){}方法.
>根模板是ng1模板.即在index.html中,您应该只有ng1组件或降级的ng2组件.您可以将ng2组件作为根,但是您需要先将其降级.

官方升级指南包含DOM结构的示例:

enter image description here

…确保ng2注射器具有ng1所需的所有提供者.

angularjs – 如何配置Angular2应用程序使用Maven的打字稿?

angularjs – 如何配置Angular2应用程序使用Maven的打字稿?

我是Angular2.0的新手。我的项目技术栈是Angular 2.0 with typcript和spring作为后端。我不想使用节点服务器指示编译我的前端,但我需要使用TOMCAT和Maven。我有几个问题。

>我想,节点服务器为每个.ts文件生成.js和.js.map,因为浏览器只能理解.js文件。我的理解是正确的吗?如何使用Maven和Tomcat完成此任务?
>我想使用Maven从头开始构建我的应用程序。我更喜欢凉亭作为前端任务经理。

任何人都可以有一步一步的指南创建AngularJS2 Spring应用程序使用’bower或一些其他工具前台任务管理,如文件缩小,创建应用程序支架’和’Maven的后端任务管理’?我欢迎任何建议。

我们的其他应用程序团队目前使用Angular 1.4与Spring,已经使用TOMCAT用于WAR部署和Maven用于所有其他任务。他们使用bower作为前端任务管理工具。如果任何人使用这样的任务管理工具设置他们的Angular2项目,任何建议将是有帮助的。任何设置指南将是伟大的。

提前致谢

我在使用maven的Angular 2 Spring Boot应用程序中使用typescript .ts文件。我运行npm安装依赖和npm运行tsc通过exec-maven插件将.ts文件转换为.js。

下面是我的pom.xml中的插件部分。在我的应用程序中,pacakge.json,tsconfig.json和typings.json都在src / main / resources路径下,因此在路径下运行npm tasks

pom.xml

<parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>1.3.5.RELEASE</version>
</parent>

<packaging>war</packaging>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>exec-npm-install</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>${project.basedir}/src/main/resources</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
                <execution>
                    <id>exec-npm-run-tsc</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <workingDirectory>${project.basedir}/src/main/resources</workingDirectory>
                        <executable>npm</executable>
                        <arguments>
                            <argument>run</argument>
                            <argument>tsc</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

我的Angular2 Spring Boot应用程序文件夹结构如下

src/main/resources
                  /app          - .ts and converted .js
                  /css
                  /images
                  /js           - systemjs.config.js is also placed here
                  /node_modules - generated by npm install and will include in war
                  /typings
                  application.properties
                  package.json
                  tsconfig.json
                  typings.json

src/main/webapp
               /WEB-INF
                       /jsp     - all .jsp files

在.jsp文件头部分,包括systemjs.config.js

<script type="text/javascript" src="webjars/zone.js/0.6.12/dist/zone.js"></script>
<script type="text/javascript" src="webjars/reflect-Metadata/0.1.3/Reflect.js"></script>
<script type="text/javascript" src="webjars/systemjs/0.19.27/dist/system.js"></script>
<script type="text/javascript" src="js/systemjs.config.js"></script>

这里也是我的WebMvcConfigurerAdapter代码映射路径

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.my.controller")
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (!registry.hasMappingForPattern("/webjars/**")) {
            registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/meta-inf/resources/webjars/");
        }
        if (!registry.hasMappingForPattern("/images/**")) {
            registry.addResourceHandler("/images/**").addResourceLocations("classpath:/images/");
        }
        if (!registry.hasMappingForPattern("/css/**")) {
            registry.addResourceHandler("/css/**").addResourceLocations("classpath:/css/");
        }
        if (!registry.hasMappingForPattern("/js/**")) {
            registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/");
        }
        if (!registry.hasMappingForPattern("/app/**")) {
            registry.addResourceHandler("/app/**").addResourceLocations("classpath:/app/");
        }
        if (!registry.hasMappingForPattern("/node_modules/**")) {
            registry.addResourceHandler("/node_modules/**").addResourceLocations("classpath:/node_modules/");
        }
    }

    @Bean
    public InternalResourceViewResolver internalViewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/jsp/");
        viewResolver.setSuffix(".jsp");
        viewResolver.setorder(1);
        return viewResolver;
    }
}

有一件事我要提到的是有一些黑客运行exec-maven-plugin在eclipse如果os是Windows或Mac。 Linux(Ubuntu)看起来没有问题。
当在Windows或Mac上从eclipse运行构建时,问题是它不能理解npm命令,并尝试找到这样的文件,即使maven构建在终端或命令窗口上完全正常。

为了解决这个问题,我做了一些调整。
对于Mac,在/ usr / bin路径下为节点和npm创建符号链接,如下所示。
但是不允许修改/ usr / bin,所以我在恢复磁盘重新启动后做

lrwxr-xr-x     1 root   wheel        17 May 22 03:01 node -> ../local/bin/node
lrwxr-xr-x     1 root   wheel        44 May 22 02:50 npm -> ../local/lib/node_modules/npm/bin/npm-cli.js

对于Windows,我做了node.bat和npm.bat文件在系统路径下如下
这样做后,maven的构建完全从eclipse和命令窗口在Windows 10。

npm.bat

@echo off
set arg1=%1
set arg2=%2
C:\Progra~1\nodejs\npm.cmd %arg1% %arg2%

asp.net-mvc – 使用.net mvc在IIS角度2应用程序上发布

asp.net-mvc – 使用.net mvc在IIS角度2应用程序上发布

我用mvc设置了一个有角度的2应用程序.
我正在使用typescript 2.3.1.0 for visual studio.
我安装了节点模块并添加了对angular 2的引用.

意见 – >首页 – >索引文件 –

@{
    ViewBag.Title = "Home Page";
}
<div>
    <h1>Angular 2 QuickStart</h1>
</div>
<div>
    <div>
        <!-- Angular2 Code -->
        <my-app>Loading...</my-app>
        <!-- Angular2 Code -->
    </div>
</div>

我添加了所有对我的观点的引用 – >共享 – >布局文件 –

<!DOCTYPE html>
<html>
<head>
    <Meta charset="utf-8" />
    <Meta name="viewport" content="width=device-width,initial-scale=1.0">
    <Meta name="google-signin-client_id" content="118134028665-i6h833e7irrrhk0n52bgj7ve6fet4vgr.apps.googleusercontent.com">
    <title>@ViewBag.Title - My ASP.NET Application</title>

    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

    <!-- Angular2 Code -->
    <base href="/">
    <link rel="stylesheet" href="styles.css">
    <!-- polyfill(s) for older browsers -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"></script>
    <script src="https://code.angularjs.org/tools/system.js"></script>
    <script src="node_modules/core-js/client/shim.min.js"></script>
    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/reflect-Metadata/Reflect.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="systemjs.config.js"></script>
    <script>
      System.import('app').catch(function(err){ console.error(err); });
    </script>
    <!-- Angular2 Code -->

</head>
<body>
    <script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="~/JS/SocialLogin.js" type="text/javascript"></script>
    <script src="https://apis.google.com/js/platform.js" async defer></script>
    <div>
        <div>
            <div>
            </div>
            <div>
            </div>
        </div>
    </div>
    <div>
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts",required: false)
</body>
</html>

这是我的package.json文件 –

{
  "name": "angular-quickstart","version": "1.0.0","scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ","lite": "lite-server","postinstall": "typings install","tsc": "tsc","tsc:w": "tsc -w","typings": "typings"
  },"license": "ISC","dependencies": {
    "@angular/common": "2.0.0","@angular/compiler": "2.0.0","@angular/core": "2.0.0","@angular/forms": "2.0.0","@angular/http": "2.0.0","@angular/platform-browser": "2.0.0","@angular/platform-browser-dynamic": "2.0.0","@angular/router": "3.0.0","@angular/upgrade": "2.0.0","core-js": "^2.4.1","reflect-Metadata": "^0.1.3","rxjs": "5.0.0-beta.12","systemjs": "0.19.27","zone.js": "^0.6.23","angular2-in-memory-web-api": "0.0.20","bootstrap": "^3.3.6"
  },"devDependencies": {
    "concurrently": "^2.2.0","lite-server": "^2.2.2","typescript": "^2.0.2","typings":"^1.3.2"
  }
}

这是我的systemjs.config.js文件 –

(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },// map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',// angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js','@angular/common': 'npm:@angular/common/bundles/common.umd.js','@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js','@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js','@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js','@angular/http': 'npm:@angular/http/bundles/http.umd.js','@angular/router': 'npm:@angular/router/bundles/router.umd.js','@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',// other libraries
      'rxjs':                      'npm:rxjs','angular-in-memory-web-api': 'npm:angular-in-memory-web-api',},// packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',defaultExtension: 'js'
      },rxjs: {
        defaultExtension: 'js'
      },'angular-in-memory-web-api': {
        main: './index.js',defaultExtension: 'js'
      }
    }
  });
})(this);

当节点模块文件夹未包含在项目中时,它是成功构建的,当我运行它时工作正常.

一旦我发布它并将发布移动到开发服务器并将其部署在IIS上,mvc就会运行但是角度2不会.
这些是我得到的错误 –

Error of angular 2

我假设我得到这个错误,因为缺少节点模块文件夹.

如果我回到项目并在项目中包含节点模块并构建它,我会收到这些错误 –

Severity Code Description Project File Line Suppression State
Error Build:File
‘E:/MyApp/MyApp/MyApp.Site/node_modules/browser-sync/node_modules/rx/ts/core/linq/observable/mergeproto.ts’
not found. MyApp.Site E:\MyApp\MyApp\MyApp.Site\tsc

Severity Code Description Project File Line Suppression State
Error Build:File
‘E:/MyApp/MyApp/MyApp.Site/node_modules/browser-sync/node_modules/rx/ts/core/linq/observable/zipproto.ts’
not found. MyApp.Site E:\MyApp\MyApp\MyApp.Site\tsc

我该如何解决这个问题?
在iis上使用.net mvc部署angular 2应用程序的正确方法是什么?
在此项目中包含节点模块的正确方法是什么?

谢谢!

解决方法

我也面临同样的问题,没有得到适当的解决方案,
所以我使用了另一种解决方案.

>在IIS上独立部署MVC(API).
>使用ng prod单独构建Angular 2应用程序.
>部署Angular 2应用程序(dist文件夹)作为静态网站
    在IIS上.
>在Angular 2 API中使用已部署的API进行数据访问.

如果你有任何错误ping我.

今天关于在IE中调试角度2的打字稿应用程序的分享就到这里,希望大家有所收获,若想了解更多关于anglejs – 需要(多)角度的打字稿、angularjs – $scope的提供者!在角度2应用程序中使用角度1指令时出错、angularjs – 如何配置Angular2应用程序使用Maven的打字稿?、asp.net-mvc – 使用.net mvc在IIS角度2应用程序上发布等相关知识,可以在本站进行查询。

本文标签: