angularjs - Angular.js and Require.Js -
i studying angular.js , require.js @ moment. encountered issue here while using 2 together. example in html have simple {{3+3}}. found out evaluated 6 few seconds after loaded. user can see whole process. not me. not want delay here. can explain why happened? because doing manually bootstrap.
this main.js require , bootstrap code.
require.config({ paths: { jquery: 'lib/jquery/jquery-1.9.1.min', bootstrap: 'lib/bootstrap/bootstrap.min', angular: 'lib/angular/angular.min' }, baseurl: '/scripts', shim: { 'angular': { 'exports': 'angular' }, 'bootstrap': { deps: ['jquery'] } }, priority: [ 'angular' ] }); require(['angular', 'app/admin/app.admin', 'app/admin/app.admin.routes', 'app/admin/index/index', 'app/admin/app.admin.directives'], function (angular, app) { 'use strict'; angular.element(document).ready(function () { angular.bootstrap(document, ['app.admin']); }); }); cheers
as you're loading dependencies require.js before bootstraping angular, user have wait files loaded before application starts. , because html loaded first before scripts, it's raw content made visible user while.
if don't wan't user see content of html element before it's processed angular, use ngcloak directive made this. take @ entry of documentation: http://docs.angularjs.org/api/ng.directive:ngcloak. directive sets element's style it's hidden , when angular bootstraps , finishes processing html element's style set visible, showing compiled html.
update:
but above solution won't work straightaway in case (because angular library script have loaded before template body — included in document's head), should additionally include following styling in head section of document:
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none; } this angular appends page styles after being loaded.
yet solution not insert {{ }} bindings directly inside elements' bodies, using ng-bind, ng-bind-template , ng-bind-html-unsafe directives instead. can find descriptions here:
http://docs.angularjs.org/api/ng.directive:ngbind http://docs.angularjs.org/api/ng.directive:ngbindtemplate http://docs.angularjs.org/api/ng.directive:ngbindhtmlunsafe
Comments
Post a Comment