angularAMD:view不等待加载js

时间:2014-10-28 04:41:12

标签: angular-amd

我对angularAMD有疑问。 Main.js:

require.config({
    baseUrl: "/assets/static/app",
    paths: {
        app:                'app',
        angular:            '../angular/angular',
        angularAMD:         '../require/angularAMD',
        angularRoute:       '../angular/angular-route',

        angularRedactor:    '../angular/angular-redactor',
        angularUpload:      '../angular/angular-upload',
        angularSanitize:    '../angular/angular-sanitize',
        angularAnimate:     '../angular/angular-animate',
        angularBootstrap:   '../angular/angular-bootstrap',

        jquery:             '../jquery/jquery.min',
        bootstrap:          '../bootstrap/bootstrap.min',

    },
    shim: {
        bootstrap:          ['jquery'],
        angularAMD:         ['angular'],
        angularRoute:       ['angular'],    
        angularBootstrap:       ['angular','bootstrap'],
        angularAnimate:         ['angular'],
        angularSanitize:        ['angular'],

    },
    deps: ['app']
});

App.js:

define(
    ['angularAMD','angularRoute','angularBootstrap','angularSanitize','angularAnimate'], function (angularAMD) {

    var app = angular.module("app", ['ngRoute','ngBoostrap','ngSanitize','ngAnimate']);

    app.config(function($locationProvider, $logProvider) {
        $locationProvider.html5Mode(true);
        $logProvider.debugEnabled(true);
    });

    //Настройка роутов
    app.config(function($routeProvider) {

    $routeProvider
           .when('/',
                    angularAMD.route({
                        templateUrl: '/welcome',
                        controller: 'WelcomeCtrl',
                        controllerUrl: 'controllers/guest/welcome'
                    })
               )
            .when('/news',
                angularAMD.route({
                    templateUrl: '/news',
                    controller: 'NewsCtrl',
                    controllerUrl: 'controllers/guest/news'
                })
            )
            .when('/news/:post_url',
                angularAMD.route({
                    templateUrl:  function(params){return '/news/post'},
                    controller: 'NewsPostCtrl',
                    controllerUrl: 'controllers/guest/news_post'
                })
            )
            .when('/page/:page_url',
                angularAMD.route({
                    templateUrl:function(params){ return '/page/'+params.page_url},
                    controller: 'PageCtrl',
                    controllerUrl: 'controllers/guest/page'
                })
            )
            .otherwise({redirectTo: '/'});

    });

    app.run();

    return angularAMD.bootstrap(app);
});

Yii框架:

public function render($view,$data=null,$return=false)
    {
        if (strpos($_SERVER['HTTP_ACCEPT'],"application/json") === 0){

            $path_view = '/';
            $path_view .= $this->id.'/'.$view;
            sleep(1.5);//crutches =(
            $this->renderPartial($path_view, $data);
            Yii::app()->end();
        } else {
            parent::render($view,$data,$return);
        }
    }

如果内容在js控制器之前加载:我有错误“Argument'WelcomeCtrl'不是函数,得到了未定义”。我必须在内容请求上延迟1.5秒。这不正常。内容必须等待加载js。请帮帮我。

0 个答案:

没有答案