我是一个有角度的新手。
可以找到更具描述性的错误here:
此错误意外地突然出现。我试图包含BootstrapDialog但是加载序列导致bootstrap-dialog.js在调用它的模块之后加载。
当我调试bootstrap-dialog时,我发现如果我逐步完成脚本,直到另一个<script>
执行,则错误没有发生。这种行为让我感到困惑。希望有更多角色经验的人可以解开这个问题。
脚本参考:
<scriptk="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-route.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-dialog.js"></script>
<script async defer src="js/recaptcha.js"></script>
<script async defer src="https://use.fontawesome.com/9f2a0d923f.js"></script>
<script async defer src="js/pages.js"></script>
<script async defer src="js/common.js"></script>
完成index.html:
<!DOCTYPE html>
<html lang="en" data-ng-app="wtApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> -->
<meta name="fragment" content="!">
<meta name="google-site-verification" content="k-yDmol0MzU1QXaTTGlhNa_gVLzUs" />
<title>Writer's Tryst, where authors, publishers, producers, agents meet.</title>
<meta name="description" content="A better way for writers to find publishers, producers and agents" />
<meta name="keywords" content="Writer's Tryst, authors, publishers, producers, agents, writers, genres, manuscripts, books, find, meet." />
<base href="/" />
<link href='https://fonts.googleapis.com/css?family=Lobster+Two:700italic' rel='stylesheet' type='text/css' />
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/font-awesome.min.css" />
<link rel="stylesheet" href="css/normalize-min.css" />
<link rel="stylesheet" href="css/bootstrap-dialog.css" />
<link rel="stylesheet" href="css/main.css" />
<link rel="stylesheet" href="css/shares.css" />
<link rel="shortcut icon" href="img/icons/writers-tryst.png" />
</head>
<body data-ng-controller="mainController">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-79802711-1', 'auto');
ga('send', 'pageview');
</script>
<header>
<nav class="navbar navbar-light">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#Writers-Tryst">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div style="display: inline-block">
<a class="navbar-brand" href="#"><img id="logo" src="img/writers-tryst-logo-min.png" alt="logo" /></a><br/><br/>
<div id="shares" class="row">
<!-- Twitter -->
<a href="http://twitter.com/share?url=writers.tryst.ron-tornambe.com&text=<TEXT>&via=<VIA>" target="_blank" title="twitter" class="share-btn twitter">
<i class="fa fa-twitter"></i>
</a>
<!-- Facebook -->
<a href="http://www.facebook.com/sharer/sharer.php?u=http://writers.tryst.com" target="_blank" title="facebook" class="share-btn facebook">
<i class="fa fa-facebook"></i>
</a>
<!-- StumbleUpon (url, title)
<a href="http://www.stumbleupon.com/submit?url=http://writers.tryst.com&title=<TITLE>" target="_blank" class="share-btn stumbleupon" title="stumble-upon">
<i class="fa fa-stumbleupon-circle"></i>
</a> -->
<!-- Reddit (url, title)
<a href="http://reddit.com/submit?url=http://writers.tryst.com&title=<TITLE>" target="_blank" class="share-btn reddit" title="reddit">
<i class="fa fa-reddit-square"></i>
</a> -->
<!-- LinkedIn -->
<a href="http://www.linkedin.com/shareArticle?url=http://writers.tryst.com&title=<TITLE>&summary=<SUMMARY>&source=<SOURCE_URL>" target="_blank" title="linked-in" class="share-btn linkedin">
<i class="fa fa-linkedin"></i>
</a>
<!-- Google Plus -->
<a href="https://plus.google.com/share?url=writers.tryst.ron-tornambe.com" target="_blank" title="google+" class="share-btn google-plus">
<i class="fa fa-google-plus"></i>
</a>
</div>
</div>
</div> <!--navbar-header-->
<div class="collapse navbar-collapse" id="Writers-Tryst">
<ul class="nav navbar-nav">
<li class="active"><a id="homepage" href="#/"><i class="acctive glyphicon glyphicon-home fa fa-home"></i> Home</a></li>
<li><a href="#writers" id="writers-link" class="fa fa-book" > Writers</a></li>
<li><a href="#enablers" id="enablers-link" class="fa fa-thumbs-o-up" > Enablers</a></li>
<li><a href="#about" class="fa fa-info-circle"> About</a></li>
<li><a href="#privacy" class="fa fa-user-secret"> Privacy/Rules</a></li>
<li><a href="#contact" class="fa fa-envelope-o"> Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a id="login" href="#log-in"><i class="fa fa-sign-in"></i> Log-In</a></li>
<li><a id="accounts-link" href="#accounts"><i class="fa fa-user hidden"></i> Create Account</a></li>
<li class="dropdown" data-toggle="popover" data-trigger="hover" data-placement="bottom" >
<button class="btn btn-custom-primary dropdown-toggle fa fa-user" style="margin-top: 8px;" data-html="true" type="button" id="user-dropdown-link" data-toggle="dropdown"><span class="caret"></span></button></a>
<ul class="dropdown-menu" role="menu" data-aria-labelledby="create-account-link">
<li><a id="update-profile" href="#update-profile" class="fa fa-database"> Update profile</a></li>
<li><a id="manage-uploads" href="#manage-uploads" class="fa fa-book"> Manage uploads</a></li>
<li><a id="review-submissions" href="#review-submissions" class="fa fa-book"> Review Submissions</a></li>
<li><a id="update-submissions" href="#update-submissions" class="fa fa-book"> Update Reviews</a></li>
</ul>
</li>
<li ><a id="reset-pwd-link" href="#reset-pwd"></a></li>
</ul>
</div> <!--navbar-collapse-->
</div> <!--container fluid-->
</nav>
</header>
<div>
<div id="message" class="alert m-t-10 m-b-10"></div>
<div id="main" class="content">
<!-- angular templating -->
<!-- this is where content will be injected -->
<div data-ng-view></div>
</div>
</div>
<div class="panel panel-default panel-transparent">
<div id="foot" class="text-right small">© 2016 Ronald Tornambe, Inc.</div>
</div>
<div id="recaptchaModal" class="modal fade hidden" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<div class="capatcha">
<div id="recaptcha-elements"></div>
</div>
<button type="button" id="closeModal" class="btn btn-custom-success btn-block" disabled data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-route.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-dialog.js"></script>
<script async defer src="js/recaptcha.js"></script>
<script async defer src="https://use.fontawesome.com/9f2a0d923f.js"></script>
<script async defer src="js/pages.js"></script>
<script async defer src="js/common.js"></script>
<script>
$("#drop-toggle-1").on("click", function (e) {
e.preventDefault();
});
$("#accounts-link").addClass("hidden");
angular.element(document).ready(function () {
$("#review-submissions").on("mousedown", function () {
sessionStorage.setItem("submissions", "review");
});
$("#update-submissions").on("mousedown", function () {
sessionStorage.setItem("submissions", "update");
});
});
</script>
</body>
</html>
app.js
var navbarColor = "#f89c00";
var navbarSelectedColor = "#e05c00";
var wtApp = angular.module('wtApp', ['ngRoute'])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
})
// route for the writers page
.when('/writers', {
templateUrl: 'pages/writers.html',
controller: 'writersController'
})
// route for the enablers page
.when('/enablers', {
templateUrl: 'pages/enablers.html',
controller: 'enablersController'
})
// route for privacy/rues
.when('/privacy', {
templateUrl: 'pages/privacy.html',
controller: 'privacyController'
})
// route for the about page
.when('/about', {
templateUrl: 'pages/about.html',
controller: 'aboutController'
})
// route for the contact pagefa
.when('/contact', {
templateUrl: 'pages/contact.html',
controller: 'contactController'
})
// route for the log-in page
.when('/log-in', {
templateUrl: 'pages/login.html',
controller: 'loginController'
})
// route for the create account
.when('/accounts', {
templateUrl: 'pages/accounts.html',
controller: 'createAccountController'
})
// route for the update profile
.when('/reset-pwd', {
templateUrl: 'pages/reset-pwd.html'
})
// route for the update profile
.when('/update-profile', {
templateUrl: 'pages/update-profile.html',
controller: 'updateProfileController'
})
.when('/review-submissions', {
templateUrl: 'pages/review-submissions.html',
controller: 'reviewSubmissionsController'
})
.when('/update-submissions', {
templateUrl: 'pages/review-submissions.html',
controller: 'updateSubmissionsController'
})
// route for manage uploads
.when('/manage-uploads', {
templateUrl: 'pages/manage-uploads.html',
controller: 'manageUploadsController'
});
// $locationProvider.html5Mode(true);
});
// create the controller and inject Angular's $scope
wtApp.controller('mainController', function($scope) {
$scope.example2model = []; $scope.example2data = [ {id: 1, label: "David"}, {id: 2, label: "Jhon"}, {id: 3, label: "Danny"}]; $scope.example2settings = {displayProp: 'id'};
resetNavbar();
$("a[href$='']").css({color:navbarSelectedColor});
});
wtApp.controller('writersController', function ($scope, $timeout) {
resetNavbar();
$("a[href$='writers']").css({ color: navbarSelectedColor });
$timeout(function () {
var form = $("#form-writers");
var sw = (form.width() - 232) / 2;
// $("#recaptcha-elements").parent().css("margin-left", sw );
}, 100);
});
wtApp.controller('enablersController', function ($scope) {
resetNavbar();
$("a[href$='enablers']").css({ color: navbarSelectedColor });
});
wtApp.controller('aboutController', function($scope) {
resetNavbar();
$("a[href$='about']").css({color:navbarSelectedColor});
});
wtApp.controller('privacyController', function($scope) {
resetNavbar();
$("a[href$='privacy']").css({color:navbarSelectedColor});
});
wtApp.controller('contactController', function($scope) {
resetNavbar();
$("a[href$='contact']").css({color:navbarSelectedColor});
});
wtApp.controller('loginController', function ($scope) {
// clearAuthenticationFlag();
resetNavbar();
$("a[href$='log-in']").css({ color: navbarSelectedColor });
});
wtApp.controller('createAccountController', function ($scope, $timeout) {
resetNavbar();
$("a[href$='create-account']").css({ color: navbarSelectedColor });
// clearAuthenticationFlag();
$scope.$on('$viewLoaded', function (event) {
$timeout(function () {
var form = $("#form-accounts");
if (form.length) {
form.get(0).reset();
}
}, 100);
});
});
wtApp.controller('ResetPasswordController', function ($scope) {
resetNavbar();
});
wtApp.controller('updateProfileController', function ($scope) {
resetNavbar();
$("a[href$='update-profile']").css({ color: navbarSelectedColor });
});
wtApp.controller('reviewSubmissionsController', function ($scope) {
resetNavbar();
$("a[href$='review-submissions']").css({ color: navbarSelectedColor });
});
wtApp.controller('updateSubmissionsController', function ($scope) {
resetNavbar();
$("a[href$='update-submissions']").css({ color: navbarSelectedColor });
});
wtApp.controller('manageUploadsController', function ($scope) {
resetNavbar();
$("a[href$='manage-uploads']").css({ color: navbarSelectedColor });
});
function resetNavbar() {
$(".navbar-collapse a").not("a[href='#']").each(function () {
$(this).css({ 'color': navbarColor })
});
}
答案 0 :(得分:1)
我认为问题在于 async 属性传递给脚本标记。不知何故,您的pages.js在角度路线加载之前首先加载。如果有帮助,请尝试删除该标记
有关此主题的更多信息,您可以访问 http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html