私はComponent Routerでバインドするのに苦労しています。コンポーネントルータのバインディング - 角度1.5
開発者ガイドでは、コンポーネントで$ scopeを使用しないでください。したがって、オブジェクトはバインディングを通過する必要があります。
の例に基づいて:
HTML::
<div ng-app="app" ng-controller="MainCtrl as ctrl">
{{ ctrl.hero.name }}
<app></app>
</div>
Javascriptを: https://docs.angularjs.org/guide/componentとhttps://docs.angularjs.org/guide/component-router私が思い付いた
'use strict';
var app = angular.module('app', [
'ngComponentRouter',
'testComponent',
])
.config(function($locationProvider) {
$locationProvider.html5Mode(true);
})
.value('$routerRootComponent', 'app')
.controller('MainCtrl', function(){
this.hero = {
name: 'Spawn'
};
})
.component('app', {
template: '<ng-outlet></ng-outlet>',
$routeConfig: [
{path: '/test', name: 'Test', component: 'testComponent'},
],
})
var testComponent = angular.module('testComponent', []);
testComponent.component('testComponent', {
template: '<span>Name: {{$ctrl.hero.name}}</span>',
controller: TestComponentController,
bindings: {
hero: '=',
}
});
function TestComponentController() {
}
しかし、 "スポーン" を<span>Name: {{$ctrl.hero.name}}</span>
表示されませんか何でも
説明をいただきありがとうございます – srokatonie