2016-05-18 45 views
0

运行我有这个代码不运行,请,如果您有任何想法如何找到一个解决方案,将是很好,并感谢 这是index.html的脚本不templateurl与angularjs 2

<!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”没有得到执行。如果您希望在组件加载,你应该在这个类中使用ngOnInit挂钩方法来运行的东西任何帮助将不胜感激 感谢

回答

0

@Component({ 
    selector: 'my-app', 
    template: ` 
    (...) 
    ` 
}) 
export class AppComponent { 
    ngOnInit() { 
    // do something 
    } 
} 
+0

你好,感谢评论,但我想执行一个链接,而不是代码 ,这是角度2的方式 谢谢 –

+0

@VFXGamingMenjli它是禁止的https://angular.io/docs/ts/latest/guide/ template-syntax.html#!#html – yurzui

+0

@yurzui,在一些特殊情况下是否可以重写此行为? –