3
我正在嘗試在UI路由器中使用components
(而不是controllers
和templates
)。但是這不起作用。
我跟隨this文章從他們的網站。
Plunk
HTML:如何使用ui路由器使用角度組件?
<body ng-app="myApp">
<h1>Help!</h1>
<a ui-sref="mypage">mypage</a>
<ui-view></ui-view>
</body>
JS:
// Register
angular.module('myApp', ['ui.router']);
// config
angular.module('myApp').config(function($stateProvider) {
$stateProvider.state({
name: 'mypage',
url: '/mypage',
component: "newComponent" // cant use this.
})
});
//component
angular.module('myApp').component('newComponent', {
template: "<h1> THis is from component <h1>"
});
我沒有得到結果,也沒有任何錯誤。我在這裏錯過了什麼?
在此先感謝。
開關的版本,然後單擊庫[工作正常這裏(HTTPS:/ /plnkr.co/edit/Cpph8siwPTnJYf5ihniO?p=preview) – charlietfl