gpt4 book ai didi

javascript - 从 ng-app 转到手动 Bootstrap 不起作用,出现空白页面

转载 作者:行者123 更新时间:2023-11-28 04:26:51 24 4
gpt4 key购买 nike

为了运行混合 Angular 1 和 Angular 2,我遵循以下准则:https://angular.io/guide/upgrade#upgrading-with-ngupgrade

我遇到的一个问题是从使用 ng-app 引导切换到手动引导方法,因为升级需要手动引导才能工作。下面的 ng-app 引导方法工作得很好:

    <!DOCTYPE html SYSTEM "about:legacy-compat">
<html ng-app="c2c" xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" class="no-js">

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<title>c2c</title>
<link href='https://fonts.googleapis.com/css?family=Michroma' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Prompt:100,200,300,400,500,600,700,800' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto:100,200,300,400,500,700,900' rel='stylesheet' type='text/css'>
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

<!-- build:css({.tmp/serve,src}) styles/vendor.css -->
<!-- bower:css -->
<!-- run `gulp inject` to automatically populate bower styles dependencies -->
<!-- endbower -->
<!-- endbuild -->

<!-- build:css({.tmp/serve,src}) styles/app.css -->
<!-- inject:css -->
<!-- css files will be automatically insert here -->
<!-- endinject -->
<!-- endbuild -->
</head>

<body ng-controller="UserController as mainApp">
<!--[if lt IE 10]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="container-fluid">
<div class="row">
<div class="c2c-header"></div>
</div>
<div class="row" ng-if="emailClass!='email'">
<div class="c2c-navbar"></div>
</div>
<div class="row">
<!--<div ng-if="emailClass!='email'" class="talent-aside col-xs-3 col-sm-3 col-md-2 col-lg-2" ng-if="mainApp.hasPermission('DealPoint.VIEW')"></div>-->
<div class="talent-aside col-xs-3 col-sm-3 col-md-2 col-lg-2"></div>
<div class="talent-content body-bg col-xs-9 col-sm-9 col-md-10 col-lg-10">
<div class="ui-view"></div>
</div>
</div>
</div>

<!-- <div class="pageloader" ng-if="loader">
<img src="app\assets\images\balls.gif" width="100" height="100" class="loaderImage" />
<span class="loaderText" ng-if="loadingText.length>0">{{loadingText}}</span>
</div>
-->


<!-- build:js(src) scripts/vendor.js -->
<!-- bower:js -->
<!-- run `gulp inject` to automatically populate bower script dependencies -->
<!-- endbower -->
<!-- endbuild -->
<!--<script src="../bower_components/angular-filter/dist/angular-filter.min.js"></script>
<script src="../bower_components/angular-sanitize/angular-sanitize.min.js"></script>-->

<!-- build:js({.tmp/serve,.tmp/partials,src}) scripts/app.js -->
<!-- inject:js -->
<!-- js files will be automatically insert here -->
<!-- endinject -->

<!-- inject:partials -->
<!-- angular templates will be automatically converted in js and inserted here -->
<!-- endinject -->
<!-- endbuild -->



</body>

</html>

但是当我切换到手动引导方法时,我得到一个空白页面,没有控制台错误:

<!DOCTYPE html SYSTEM "about:legacy-compat">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" class="no-js">

<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<title>c2c</title>
<link href='https://fonts.googleapis.com/css?family=Michroma' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Prompt:100,200,300,400,500,600,700,800' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto:100,200,300,400,500,700,900' rel='stylesheet' type='text/css'>
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

<!-- build:css({.tmp/serve,src}) styles/vendor.css -->
<!-- bower:css -->
<!-- run `gulp inject` to automatically populate bower styles dependencies -->
<!-- endbower -->
<!-- endbuild -->

<!-- build:css({.tmp/serve,src}) styles/app.css -->
<!-- inject:css -->
<!-- css files will be automatically insert here -->
<!-- endinject -->
<!-- endbuild -->
</head>

<body ng-controller="UserController as mainApp">
<!--[if lt IE 10]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="container-fluid">
<div class="row">
<div class="c2c-header"></div>
</div>
<div class="row" ng-if="emailClass!='email'">
<div class="c2c-navbar"></div>
</div>
<div class="row">
<!--<div ng-if="emailClass!='email'" class="talent-aside col-xs-3 col-sm-3 col-md-2 col-lg-2" ng-if="mainApp.hasPermission('DealPoint.VIEW')"></div>-->
<div class="talent-aside col-xs-3 col-sm-3 col-md-2 col-lg-2"></div>
<div class="talent-content body-bg col-xs-9 col-sm-9 col-md-10 col-lg-10">
<div class="ui-view"></div>
</div>
</div>
</div>

<!-- <div class="pageloader" ng-if="loader">
<img src="app\assets\images\balls.gif" width="100" height="100" class="loaderImage" />
<span class="loaderText" ng-if="loadingText.length>0">{{loadingText}}</span>
</div>
-->


<!-- build:js(src) scripts/vendor.js -->
<!-- bower:js -->
<!-- run `gulp inject` to automatically populate bower script dependencies -->
<!-- endbower -->
<!-- endbuild -->
<!--<script src="../bower_components/angular-filter/dist/angular-filter.min.js"></script>
<script src="../bower_components/angular-sanitize/angular-sanitize.min.js"></script>-->

<!-- build:js({.tmp/serve,.tmp/partials,src}) scripts/app.js -->
<!-- inject:js -->
<!-- js files will be automatically insert here -->
<!-- endinject -->

<!-- inject:partials -->
<!-- angular templates will be automatically converted in js and inserted here -->
<!-- endinject -->
<!-- endbuild -->
<script>
angular.module('c2c', [])
.controller('UserController', ['$scope', function ($scope) {
$scope.greetMe = 'World';
}]);

angular.element(function() {
angular.bootstrap(document, ['c2c']);
});
</script>


</body>

</html>

任何帮助都会很棒!谢谢!

最佳答案

您需要等待文档准备好引导 AngularJS。

改变

 angular.element(function() {
angular.bootstrap(document, ['c2c']);
});

 angular.element(document).ready(function(){
angular.bootstrap(document, ['c2c']);
});

关于javascript - 从 ng-app 转到手动 Bootstrap 不起作用,出现空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44978929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com