相关疑难解决方法(0)

有没有办法让AngularJS在开始时加载部分,而不是在需要时?

我有这样的路线设置:

var myApp = angular.module('myApp', []).
    config(['$routeProvider', function ($routeProvider) {
    $routeProvider.
        when('/landing', {
            templateUrl: '/landing-partial',
            controller: landingController
        }).
        when('/:wkspId/query', {
            templateUrl: '/query-partial',
            controller: queryController
        }).
        otherwise({
            redirectTo: '/landing'
        });
}]);
Run Code Online (Sandbox Code Playgroud)

我希望能够让angularjs在开始时下载部分内容,而不是在请求时下载.

可能吗?

angularjs

190
推荐指数
4
解决办法
11万
查看次数

在ui-router的模板中使用$ templateCache

我可以在ui-router的模板中使用$ templateCache吗?

模板将缓存在resolve部分中,我想在同一状态下使用缓存模板.

$stateProvider
.state('dashboard', {
    url: "/dashboard",
    template: function($templateCache){  
        console.log('test 2');
        return $templateCache.get('templates/template1.html'); // returns undefined
    },
    resolve:{
        baseTemplates: function($ocLazyLoad) {
            // here the template will be cached...
            return $ocLazyLoad.loadTemplateFile(['base/dashboard.html']).then(function(){
                console.log('test 1');
            });
        }
    }
})
// console prints "test 2" before than "test 1"
Run Code Online (Sandbox Code Playgroud)

更新:(+代码更新)

我认为我的代码的解决部分存在问题.因为它在模板部分之后运行!并导致返回$ templateCache.get未定义.

我使用ocLazyLoad插件来缓存模板,它返回一个正确的promise.

为什么模板不等待解决?

angularjs angular-ui-router

10
推荐指数
1
解决办法
2万
查看次数

标签 统计

angularjs ×2

angular-ui-router ×1