脚本没有在angularur中使用angularjs 2运行

时间:2016-05-18 16:02:45

标签: angular

我有这个代码没有运行,如果您有任何想法如何找到一个很好的解决方案并且谢谢 这是index.html

<!DOCTYPE html>
<html>
  <head>
    <title>Attribute Directives</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">
    <!-- IE required polyfills, in this exact order -->
    <script src="node_modules/es6-shim/es6-shim.min.js"></script>
    <script src="node_modules/systemjs/dist/system-polyfills.js"></script>
    <script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.js"></script>
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>
    <script>

      System.config({
        packages: {
          app: {
            format: 'register',
            defaultExtension: 'js'
          }
        //  app.run(lancerExt())
        }
      });
      System.import('app/main')
            .then(null, console.error.bind(console));
    </script>
  </head>
  <body>
    <my-app>loading...</my-app>
  </body>
</html>

这是app.Component.ts:

 import {Component} from 'angular2/core';
    import {HighlightDirective} from './highlight.directive';

    @Component({
        selector: 'my-app',
       templateUrl: 'test.html',
        directives: [HighlightDirective],

    })
    export class AppComponent { }

这是test.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script src="http://200.150.100.73:8080/adoc-web/web/MyAdoc6/MyApp/bootstrap.js">
        </script>
    </head>
    <body>
        hi how are you
    </body>
</html>

此脚本“http://200.150.100.73:8080/adoc-web/web/MyAdoc6/MyApp/bootstrap.js”未执行任何帮助将不胜感激 谢谢

1 个答案:

答案 0 :(得分:0)

如果要在加载组件时运行某些东西,则应在组件类中使用ngOnInit钩子方法:

@Component({
  selector: 'my-app',
  template: `
    (...)
  `
})
export class AppComponent {
  ngOnInit() {
    // do something
  }
}
相关问题