1

I'm making a simple test website, and I would know if we can just reload a controller, without reload the entire page.

<!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>

Here, i'm looking for refresh nav-left.

Here is my component :

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];

And where I'm trying to refresh it

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';
        }
    }
}
Druxtan
  • 1,311
  • 2
  • 15
  • 21

1 Answers1

0

You can remove and then reinsert the tag.

You have to compile the HTML to make Angular process the 'new' HTML. Take a look at the answers to this questions how this can be done.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Hmm, I don't really understand what he is trying to do... I remove my tag (OK), et then I put it back, and nothing, I know. I need to compile to make Angular relaunch the component. But the code expose don't really help me. I got an error with extend. – Druxtan Apr 22 '14 at 17:22
  • Can you please provide a bit more information about your error. Angular is changing a lot recently so the code might be a bit outdated. Maybe you might find my answer on the question easier to understand. It's all about this line `_compiler(_element.childNodes, _directiveMap)(_injector, _element.childNodes);` the other code is just to get the objects needed and some minor checks. – Günter Zöchbauer Apr 22 '14 at 17:24
  • My post is more complet. You are talking about injector, I still don't see what it's suppose to do. – Druxtan Apr 22 '14 at 17:36
  • Where am I talking about injector. `_compiler(...)` makes Angular process the tags/directives on the inserted HTML and creates components/controllers/directives for that HTML. – Günter Zöchbauer Apr 23 '14 at 06:35
  • Neither did I. I found some code examples in Angular.Dart unit tests and in the `ng-include` implementation which does something similar than the directive in my answer on the other question (`ng-include` only inserts HTML loaded from an URL instead the value of a field). – Günter Zöchbauer Apr 23 '14 at 10:07