Angularjs UI路由器,如何触发查看加载事件? [英] Angularjs ui router, how to trigger View Load events?

查看:190
本文介绍了Angularjs UI路由器,如何触发查看加载事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试UI的路由器拳头时间,但目前测试事件与我似乎无法理解如何触发$ viewContentLoaded或装入。虽然,我已经得到了stageChangeSuccess等工作!我刚推开一切 http://punkbit.com/space_competition/ 也要在这里增加了一些code。我希望当一个新的视图被加载到用户界面视图触发事件。但我想我在这里失去了一些东西!

Testing ui-router for the fist time but testing the Events at the moment and I can't seem to understand how to trigger $viewContentLoaded or Loading. Although, I've got stageChangeSuccess, etc working! I just pushed everything to http://punkbit.com/space_competition/ but also added some code here. I expected to trigger the events when a new view is loaded to ui-view. But I guess I'm missing something here!

    <div class="pure-g">
        <div class="pure-u-1" ui-view>
        </div>
    </div>


    <!-- s: template partials -->
    <script type="text/ng-template" id="menu.html">
    <div class="pure-menu pure-menu-open pure-menu-horizontal">
        <ul>
            <li><a href="#/home">home</a></li>
            <li class="pure-menu-selected"><a href="#/like_gate">like_gate</a></li>
            <li><a href="#/terms_and_conditions">terms_and_conditions</a></li>
            <li><a href="#/enter_competition">enter_competition</a></li>
        </ul>
    </div>
    </script>
    <script type="text/ng-template" id="home.html">
    <p>home.html template! fbLike is {{fbLike}}</p>
    </script>
    <script type="text/ng-template" id="enter_competition.html">
    <p>enter_competition.html template!</p>
    </script>
    <script type="text/ng-template" id="like_gate.html">
    <p>like.html template!</p>
    </script>
    <script type="text/ng-template" id="terms_and_conditions.html">
    <p>terms_and_conditions.html template!</p>
    </script>
    <!-- e: template partials -->

main.js

main.js

angular.module("space_competition", ['ui.router'])

.config(function($stateProvider, $urlRouterProvider, $locationProvider){

    $stateProvider
        .state('home', {
            url: '/home',
            templateUrl: 'home.html',
            controller: 'homeCtrl',
            resolve: {
                fb_like: 'fbLike'
            }
        })
        .state('enter_competition', {
            url: '/enter_competition',
            templateUrl: 'enter_competition.html',
            controller: 'enterCompetitionCtrl',
            resolve: {
                fb_like: 'fbLike'
            }
        })
        .state('like_gate', {
            url: '/like_gate',
            templateUrl: 'like_gate.html',
            controller: 'likeGateCtrl'
        })
        .state('terms_and_conditions', {
            url: '/terms_and_conditions',
            templateUrl: 'terms_and_conditions.html',
            controller: 'termsAndConditionsCtrl'
        });

        $urlRouterProvider.otherwise("/home");

        //$locationProvider.hashPrefix('!');

})

.run(function($rootScope){

    $rootScope
        .$on('$stateChangeStart', 
            function(event, toState, toParams, fromState, fromParams){ 
                console.log("State Change: transition begins!");
        });

    $rootScope
        .$on('$stateChangeSuccess',
            function(event, toState, toParams, fromState, fromParams){ 
                console.log("State Change: State change success!");
        });

    $rootScope
        .$on('$stateChangeError',
            function(event, toState, toParams, fromState, fromParams){ 
                console.log("State Change: Error!");
        });

    $rootScope
        .$on('$stateNotFound',
            function(event, toState, toParams, fromState, fromParams){ 
                console.log("State Change: State not found!");
        });

    $rootScope
        .$on('$viewContentLoading',
            function(event, viewConfig){ 
                console.log("View Load: the view is loaded, and DOM rendered!");
        });

    $rootScope
        .$on('$viewcontentLoaded',
            function(event, viewConfig){ 
                console.log("View Load: the view is loaded, and DOM rendered!");
        });

})

.controller('homeCtrl', function($scope, fbLike){

    $scope.fbLike = fbLike.liked();

})

.controller('enterCompetitionCtrl', function($scope, fbLike){

    fbLike.liked();

})

.controller('likeGateCtrl', function($scope){

})

.controller('termsAndConditionsCtrl', function($scope){

})

.factory('fbLike', function($http, $q){

    return {

        liked: function(){
            return true;
        }

    };

});

任何人都经历可以看看吗?

Anyone experienced could have a look please ?

感谢:D

推荐答案

它看起来像你有$ viewcontentLoaded而不是$ viewContentLoaded。你忘了骆驼案例大写C?

it looks like you have "$viewcontentLoaded" instead of "$viewContentLoaded". did you forget to camel-case-capitalize the 'C'?

这篇关于Angularjs UI路由器,如何触发查看加载事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆