0

在我的页面顶部,我有

==================================================== ==============================

<html lang="en" data-ng-app="app">
<head>
    <style>
        /* This helps the ng-show/ng-hide animations start at the right place. */
        /* Since Angular has this but needs to load, this gives us the class early. */
        .ng-hide {
            display: none !important;
        }
    </style>

==================================================== ===========================

在我的身体里再往下。

==================================================== ===========================

<div class="row row-offcanvas row-offcanvas-left" data-ng-controller="dashboard" data-ng-init="vm=dashboard()">

====================================================

我想在起始页的正文中呈现以下内容

====================================================

<span class="bold">{{vm.title}}</span> Messages

====================================================

这仅在起始页上。我想使用 Angular 进行绑定而不是单页。有任何想法吗。我尝试创建返回第一页的路线,但如您所知,它导致了无限循环。我认为 ng-init 是要走的路,但它没有用。谢谢

仪表板是一个控制器。这是来自 John Papa 在 Pluralsight 上的 Angular Hotowel 示例。

(function () {
    'use strict';
    var controllerId = 'dashboard';
    angular.module('app').controller(controllerId, ['common', 'datacontext', dashboard]);

    function dashboard(common, datacontext) {
        var getLogFn = common.logger.getLogFn;
        var log = getLogFn(controllerId);

        var vm = this;
        vm.news = {
            title: 'hottowel',
            description: 'Welcome'
        };
        vm.messageCount = 0;
        vm.people = [];
        vm.title = 'Dashboard';

        activate();

        function activate() {
            var promises = [getMessageCount(), getPeople()];
            common.activateController(promises, controllerId)
                .then(function () { log('Activated Dashboard View'); });
        }

        function getMessageCount() {
            return datacontext.getMessageCount().then(function (data) {
                return vm.messageCount = data;
            });
        }

        function getPeople() {
            return datacontext.getPeople().then(function (data) {
                return vm.people = data;
            });
        }
    }
})();
4

2 回答 2

1

为了让 yoh 能够调用dashboard(),它应该是控制器作用域上的一个函数(事实并非如此)。
我相信您正在尝试使用controller as语法(更多信息):

<div ... ng-controller="dashboard as vm">
    ...
    {{vm.title}}
于 2014-05-28T05:23:55.040 回答
0

如果你愿意,你不能使用路由器,也不要在你的 Angular 应用程序中设置路由,这样它就不会与你的后端路由器冲突

于 2014-05-28T02:42:43.203 回答