我已将其精简为最基本的数据,但我对发生的事情感到困惑。我在 Angular 2 中收到选择器未找到错误。试图找出问题所在,它在一小时前工作,现在我添加了逗号或空格或做了一些事情来打破它,但我无法弄清楚我改变了什么!安排
感谢任何帮助!谢谢!
boot.ts
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent);
app.component.ts
import {Component} from 'angular2/core';
@Component({
selector: 'app',
template: `
<h1>component works!</h1>
`
})
export class AppComponent {
}
index.html
<!doctype>
<html>
<head>
<base href="/">
<title>Angular 2 Boilerplate</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Load libraries -->
<!-- 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.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.js"></script>
<link rel="stylesheet" href="src/css/app.css">
</head>
<body>
<my-app>Loading...</my-app>
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
</body>
</html>
最佳答案
在您的 html 文件中,您需要更改 <my-app>
至<app>
....
</head>
<body>
<app>Loading...</app> <!-- this should match your root component selector -->
<script>
....
关于javascript - 获取选择器 "app"与任何元素都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37897879/