重新加载控制器

时间:2014-04-22 16:08:01

标签: dart angular-dart

我正在制作一个简单的测试网站,我知道我们是否可以重新加载控制器,而无需重新加载整个页面。

<!DOCTYPE html>
<html ng-app>
    <head lang="fr">
        <meta charset="UTF-8">
        <title>The Office</title>
        <link rel="stylesheet" href="./css/style.css">
        <script type="application/dart" src="main.dart"></script>
    </head>
    <body>
    <div class="wrapper">

        <nav nav-left ng-cloak>
            <header>
                <div ng-bind-html="user_infos"></div>
            </header>
            <ul>
                <li ng-repeat="content in ctrl.menu_list"><a ng-class="ctrl.menu_class[content]" ng-click="ctrl.itemSelected(content)" href="{{ctrl.getLink(content)}}">{{content}}</a></li>
            </ul>
        </nav>

        <main>
            <h1>The Office</h1>
            <ng-view></ng-view>
        </main>

    </div>
    </body>
</html>

在这里,我正在寻找刷新nav-left。

这是我的组件:

import 'package:angular/angular.dart';

@Component(
    selector: 'nav-left',
    templateUrl: "/view/nav_left.html",
    cssUrl: "/css/style.css",
    publishAs: 'ctrl')
class NavLeft {
    Scope scope;
    ...

    NavLeft(this.scope);

    void    itemSelected(item) {
        menu_class.forEach((k, v) {
            menu_class[k] = (v == 'active') ? '' : v;
            menu_class[k] = (k == item) ? 'active' : '';
        });
    }

    String  getLink(item) =>
        menu_link[item];

我试图刷新它的地方

library register;

import  'package:angular/angular.dart';
import  'package:Lawfice/service/ask_Server.dart';
import 'package:password_hasher/password_hasher.dart';
import  'dart:convert';
import  'dart:html';

@Controller(
    selector: '[register-module]',
    publishAs: 'ctrl')
class registerModule {
    Router router;
    Scope   scope;
...

    registerModule(this.router, this.scope);

    ...

    void    submit() {
        if (checked_email == 'OK' && checked_pass == 'OK') {
            Map<String, Map> data = {};
            var hasher = new PasswordHasher();
            var hash = hasher.hashPassword(pass1);

            data['register'] = <String, String>{};
            data['register']['email'] = email;
            data['register']['password'] = hash;
            _server.send(data).then((msg) {
                if (msg == 'OK') {
                    router.go('news', {});
                    querySelector('nav-left').remove();
                    // What I'm suppose to do here ?
                }

            });
            btn_class = 'btn btn-progress';
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您可以删除然后重新插入标记。

您必须编译HTML以使Angular处理成为“新”HTML。 看看this questions的答案如何做到这一点。