清醒热毛巾角1.2

时间:2014-02-13 13:21:29

标签: .net angularjs breeze hottowel

                   Hi all,

环境:vs 2013 express for web,hot towel angular 1.2,Breeze.WebApi2,sql server 2012 express。

当我第一次启动我的wep应用程序时,“busyindicator”没有出现,然后请求的数据出现在页面中。

为什么“busyindicator”没有出现?

正在开发我正在使用没有cookie或缓存的浏览器(firefox)。

我没有触及现有的view-viewmodels,services,config,在app.js中添加了一些功能,例如angularFileUpload(在dwonloading这个javascript之后)。

一切正常,除了“busyindicator”的问题。

该应用以view-viewmodel 客户端

开头

HTML

<section id="dashboard-view" class="mainbar" data-ng-controller="client as vm">
    <section class="matter">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <ul class="today-datas">
                        <li class="blightblue">
                            <div class="pull-left"><i class="fa fa-plane"></i></div>
                            <div class="datas-text pull-right">
                                <span class="bold">11, 12, 13 Février 2014<br />Microsoft Techdays, France</span>
                            </div>
                            <div class="clearfix"></div>
                        </li>

                        <!--<li class="borange">
                            <div class="pull-left"><i class="fa fa-envelope"></i></div>
                            <div class="datas-text pull-right">
                                <span class="bold">{{vm.messageCount}}</span> Messages
                            </div>
                            <div class="clearfix"></div>
                        </li>-->

                    </ul>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                    <div class="widget wviolet">
                        <div data-cc-widget-header title="Client"
                             allow-collapse="true"></div>
                        <div class="widget-content text-center text-info">
                            <table class="table table-condensed table-striped">
                                <thead>
                                    <tr>
                                        <th>Client Id</th>
                                        <th>Raison sociale</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr data-ng-repeat="c in vm.clients">
                                        <td>{{c.clientId}}</td>
                                        <td>{{c.raisonSociale}}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="widget-foot">
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="widget wgreen">
                        <div data-cc-widget-header title="Add a client" allow-collapse="true" />
                        <div class="widget-content text-center text-info">
                            <form name="RegisterForm" ng-submit="submit()" data-n ng-controller="vm.Ctrl">
                                <table class="table table-condensed table-striped">
                                    <tbody>
                                        <tr>
                                            <td>Raison Sociale</td>
                                            <td><input ng-model="vm.client.RaisonSociale" required width="200" /></td>
                                            <td><input type="submit" id="submit" value="Submit" /></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </form>
                        </div>
                        <div class="widget-foot">
                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</section>

JS

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

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

        var vm = this;
        vm.clients = [];
        vm.client = client;
        vm.title = 'Client';
        vm.Ctrl = Ctrl;

        var client = {
            ClientId: "",
            RaisonSociale:""
        }

        activate();

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

        function getClients() {
            return datacontext.getClients().then(function (data) {
                return vm.clients = data;
            });
        }

        function Ctrl($scope) {
            $scope.submit = function () {
                datacontext.addClient(vm.client)
                    .then(getClients());
            }
        }
    }
})();

datacontext

function getClients() {
    var manager = new breeze.EntityManager(config.remoteServiceName);
    var query = breeze.EntityQuery.from('GetClients');
    return $q.when(manager.executeQuery(query)
    .then(successCallback)
    .catch(failCallback)     // same as 'then(null, failCallback)'
    .finally(finalCallback) // sort of like 'then(finalCallback, finalCallback)'
    );
}

服务器端

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Threading.Tasks;
    using System.Web.Http;
    using System.Web.Http.Description;
    using CVApp.Models;
    using Breeze.WebApi2;
    using Breeze.ContextProvider.EF6;
    using System.Web.Mvc;
namespace CVApp.Controllers
{
    [System.Web.Mvc.Authorize]
    [BreezeController]
    public class BreezeController : ApiController
    {
        private CVIntegreEntities db = new CVIntegreEntities();
        readonly EFContextProvider<CVIntegreEntities> _contextProvider = new EFContextProvider<CVIntegreEntities>();

        [System.Web.Http.AcceptVerbs("GET")]
        [OutputCache(Duration = 259200)]
        public string Metadata()
        {
            return _contextProvider.Metadata();
        }

    .
    .
    .
            // GET api/Breeze
            [System.Web.Http.AcceptVerbs("GET")]
            public IQueryable<Client> GetClients()
            {
                return db.Clients;
            }

我在 shell.js 中已经看到“busyindicator”应该从更改路线开始:

$rootScope.$on('$routeChangeStart',
    function (event, next, current) { toggleSpinner(true); }
);

并且应该以ActivateSuccess结束:

$rootScope.$on(events.controllerActivateSuccess,
    function (data) { toggleSpinner(false); }
);

那有什么不对,为什么一开始“请等待......”没有出现?

有什么想法吗?

0 个答案:

没有答案