gpt4 book ai didi

angularjs - 无法弄清楚为什么我的 Angular View 是空白的

转载 作者:行者123 更新时间:2023-12-05 00:26:35 25 4
gpt4 key购买 nike

我正在为原型(prototype)搭建一个应用程序。我拥有一切,但是当我这样做时grunt serve我得到了我的索引页,但 View 没有初始化。我已经将它与我正在运行的其他应用程序进行了比较,但我找不到任何问题。你们中的任何人都看到了任何错误。

我应该提一下,我使用 Yeoman 来生成基本的脚手架,但我已经系统地从其中剥离了各种东西(主要是 Bower),因为我们不允许在我们的网络上使用它。所以我一直在重建一个基本的种子应用程序,它喜欢我们的网络并且可以很好地与我们的 CI 服务器配合使用。

应用程序.js

'use strict';

angular.module('angularApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ui.router'
])

.run(['$rootScope', '$state', '$stateParams',
function($rootScope, $state, $stateParams) {

// It's very handy to add references to $state and $stateParams to the $rootScope
// so that you can access them from any scope within your applications.For example,
// <li ng-class="{ active: $state.includes('contacts.list') }"> will set the <li>
// to active whenever 'contacts.list' or one of its decendents is active.
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;

$state.transitionTo('home');
}
])

.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise('/');

$stateProvider.state('home', {
//name: 'home',
url: '/',
templateUrl: 'views/main.html',
controller: 'MainCtrl'
});
}
]);

main.js
'use strict';

angular.module('angularApp', [])

.controller('MainCtrl', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
});

索引.html
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css styles/vendor.css -->
<link rel="stylesheet" href="libs/sass-bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="libs/ng-grid-2.0.7/ng-grid.css" />
<!-- endbuild -->
<!-- build:css({.tmp,app}) styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
</head>
<body ng-app="angularApp">
<!--[if lt IE 7]>
<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]-->

<!-- Add your site or application content here -->
<div ui-view></div>
test
<a ui-sref="home">home</a>

<!--[if lt IE 9]>
<script src="libs/es5-shim/es5-shim.js"></script>
<script src="libs/json3/lib/json3.min.js"></script>
<![endif]-->

<!-- build:js scripts/vendor.js -->
<script src="libs/jquery-1.10.2/jquery.js"></script>
<script src="libs/angular-1.2.10/angular.js"></script>
<script src="libs/sass-bootstrap/dist/js/bootstrap.js"></script>

<script src="libs/angular-resource/angular-resource.js"></script>
<script src="libs/angular-cookies/angular-cookies.js"></script>
<script src="libs/angular-sanitize/angular-sanitize.js"></script>

<script src="libs/ui-router-0.2.8/release/angular-ui-router.js"></script>
<script src="libs/ngStorage/ngStorage.js"></script>
<script src="libs/ng-grid-2.0.7/ng-grid-2.0.7.min.js"></script>
<!-- endbuild -->

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<!-- endbuild -->
</body>
</html>

main.html
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active"><a ng-href="#">Home</a></li>
<li><a ng-href="#">About</a></li>
<li><a ng-href="#">Contact</a></li>
</ul>
<h3 class="text-muted">angular</h3>
</div>

<div class="jumbotron">
<h1>'Allo, 'Allo!</h1>
<p class="lead">
<img src="images/yeoman.png" alt="I'm Yeoman"><br>
Always a pleasure scaffolding your apps.
</p>
<p><a class="btn btn-lg btn-success" ng-href="#">Splendid!</a></p>
</div>

<div class="row marketing">
<h4>HTML5 Boilerplate</h4>
<p>
HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites.
</p>

<h4>Angular</h4>
<p>
AngularJS is a toolset for building the framework most suited to your application development.
</p>

<h4>Karma</h4>
<p>Spectacular Test Runner for JavaScript.</p>
</div>

<div class="footer">
<p>♥ from the Yeoman team</p>
</div>

最佳答案

我看到的两件事会破坏您的 Angular 引导过程:

首先,最后包含您的 app.js:

<script src="scripts/controllers/main.js"></script>
<script src="scripts/app.js"></script>

然后, .config应该在 .run 之前:
'use strict';

angular.module('angularApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ui.router'
])

.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {}
])

.run(['$rootScope', '$state', '$stateParams',
function($rootScope, $state, $stateParams) {}
]);

关于angularjs - 无法弄清楚为什么我的 Angular View 是空白的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21993705/

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