web-dev-qa-db-ja.com

Angular2DartでルーターとRouterLinkを設定する適切な方法は何ですか

質問Angular2 DartRouterRouterLinkを設定する適切な方法は何ですか。

main.Dart

import 'package:angular2/angular2.Dart';
import 'package:angular2/router.Dart';

import 'package:angular2/src/reflection/reflection.Dart' show reflector;
import 'package:angular2/src/reflection/reflection_capabilities.Dart' show ReflectionCapabilities;


@Component(
    selector: 'home'
)
@View(
    template: '<h1>I am Home</h1><a router-link="child">Go Child</a>',
    directives: const [RouterOutlet, RouterLink]
)
class Home {}

//
//
//

@Component(
  selector: 'child'
)
@View(
    template: '<h1>I am Child</h1><a router-link="home">Go Home</a>',
    directives: const [RouterOutlet, RouterLink]
)
class Child {}

//
//
//

@Component(
  selector: 'index'
)
@View(
  template: '''
  <router-outlet></router-outlet>
            ''',
  directives: const [RouterOutlet, RouterLink]
)
class Index {
  Router router;

  Index(Router this.router) {
    router.config({ 'path': '/child', 'component': Child, 'alias': 'child'});
    router.config({ 'path': '/', 'component': Home, 'alias': 'home'});
  }

}

main() {
  reflector.reflectionCapabilities = new ReflectionCapabilities();
  bootstrap(Index, routerInjectables);
}

これが私のアプローチです:

router_link.Dartでは、newHrefnullとして戻ってきます。

onAllChangesDone() {
    if (isPresent(this._route) && isPresent(this._params)) {
      var newHref = this._router.generate(this._route, this._params);
      this._href = newHref;
      // Keeping the link on the element to support contextual menu `copy link`

      // and other in-browser affordances.
      print('newHref');
      print(newHref);
      DOM.setAttribute(this._domEl, "href", newHref);
    }

これによりエラーが発生し、ナビゲーション要求が強制終了されます。

文字列が必要ですSTACKTRACE:0 BlinkElement.setAttribute_Callback_2(Dart:_blink:7565)

1 BlinkElement.setAttribute_Callback_2_(Dart:_blink:7566)

2 Element.setAttribute(Dart:html:13673)

3 BrowserDomAdapter.setAttribute(package:angular2/src/dom/browser_adapter.Dart:258:25)

4 RouterLink.onAllChangesDone(package:angular2/src/router/router_link.Dart:66:23)

63
Jack Murphy

Angular Dart 2.0.0(リリース候補)の時点で、ルーターリンクの 正しい構文 は次のとおりです。

_<a [router-link]="['./Home']">Go Home</a>
_

値は、 Router.navigate() に渡される引数のリストです。

正しい構文 ルートを構成するための==は次のとおりです。

_@Component(
    selector: 'my-app',
    template: ...,
    directives: const [ROUTER_DIRECTIVES],
    providers: const [HeroService, ROUTER_PROVIDERS])
@RouteConfig(const [
  const Route(
      path: '/dashboard',
      name: 'Dashboard',
      component: DashboardComponent,
      useAsDefault: true),
  const Route(
      path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent),
  const Route(path: '/heroes', name: 'Heroes', component: HeroesComponent)
])
class AppComponent {
  String title = 'Tour of Heroes';
}
_
1
Mark E. Haase

app/partials/phone-list.html:

<div class="container-fluid">
  <div class="row">
    <div class="col-md-2">
      <!--Sidebar content-->

      Search: <input ng-model="query">
      Sort by:
      <select ng-model="orderProp">
        <option value="name">Alphabetical</option>
        <option value="age">Newest</option>
      </select>

    </div>
    <div class="col-md-10">
      <!--Body content-->

      <ul class="phones">
        <li ng-repeat="phone in phones | filter:query | orderBy:orderProp" class="thumbnail">
          <a href="#/phones/{{phone.id}}" class="thumb"><img ng-src="{{phone.imageUrl}}"></a>
         <a href="#/phones/{{phone.id}}">{{phone.name}}</a>
          <p>{{phone.snippet}}</p>
        </li>
      </ul>

    </div>
  </div>
</div>
0
owais ali