gpt4 book ai didi

javascript - UI View 未在 AngularJS 教程中呈现

转载 作者:行者123 更新时间:2023-12-03 06:08:19 24 4
gpt4 key购买 nike

我正在尝试遵循 Dunebook 的教程。 https://www.dunebook.com/create-an-e-commerce-site-with-angularjs/4/

由于 UI View 未渲染,我陷入了困境(我正在检查它是否按照我链接到“向 View 转换添加动画”上方链接的页面中指定的方式进行渲染)。我已经看了好几次了,我不确定我做错了什么......

代码。

鲍尔.Json

{
"name": "angular-seed",
"description": "A starter project for AngularJS",
"version": "0.0.0",
"homepage": "https://github.com/angular/angular-seed",
"license": "MIT",
"private": true,
"dependencies": {
"angular": "1.2.x",
"angular-ui-router": "",
"angular-animate": "1.2.x",
"angular-facebook": "",
"angular-loader": "1.2.x",
"angular-mocks": "~1.2.x",
"html5-boilerplate": "~4.3.0"
}
}

索引.HTML

<!DOCTYPE html>

<!--[if lt IE 7]> <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html lang="en" ng-app="myApp" class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html lang="en" ng-app="myApp" class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en" ng-app="myApp" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AngularJS tutorial</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bower_components/html5-boilerplate/css/normalize.css">
<link rel="stylesheet" href="bower_components/html5-boilerplate/css/main.css">
<link rel="stylesheet" href="css/app.css"/>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootswatch/3.1.1/simplex/bootstrap.min.css"/>
<script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script>
</head>
<body>
<div class="container">
<a class="navbar-brand" href="/">Garage Commerce</a>
<ul class="nav navbar-nav">
<li><a href="#/toys">Toys</a></li>
<li><a href="#/books">Books</a></li>
</ul>
</nav>

<!--[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]-->
<div class="container-fluid">
<div ui-view></div>
</div>

<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/x.x.x/angular.min.js"></script>
-->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/directives.js"></script>
</body>
</html>

app.js

'use strict';


// Declare app level module which depends on filters, and services
angular.module('myApp', [
'ui.router',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
])
config(['$stateProvider',
function($stateProvider) {
$stateProvider.state('add', {
url:'/add',
templateUrl: 'partials/add-products.html',
controller: 'AddProductsCtrl'
});
$stateProvider.state('category', {
url:'/:category',
templateUrl: 'partials/products.html',
controller: 'ProductsCtrl'
});
$stateProvider.state('category.products', {
url:'/:id',
templateUrl: 'partials/products.details.html',
controller: 'ProductDetailsCtrl'
});
}
])

Controller .js

'use strict';

/* Controllers */

angular.module('myApp.controllers', []).controller('ProductsCtrl', ['$scope', '$stateParams',
function($scope, $stateParams) {
$scope.category = $stateParams.category
$scope.productsListing = [{
product_id: '123',
title: ' Baby Rattles',
price: 2,
userName: 'John Doe'
}, {
product_id: '456',
title: ' Kiddy Laptop',
price: 12,
userName: 'Sandy Peters'
}

]

}
])
.controller('ProductDetailsCtrl', ['$scope', '$stateParams',function($scope, $stateParams) {
$scope.id = $stateParams.id;
$scope.product = {
'title': 'Kiddy Laptop',
'description': 'lorem lipsum do re me.',
'price': 12,
'userName': 'Sandy Peters'

}

}
]);

产品.html

<h1>{{category}}</h1>
<hr/>
<!-- 1st Column -->
<div class="col-md-5">
<div class="row-fluid listing sidebar" >
<div class="listing" ng-repeat="product in productsListing">


<h2><a ng-href="#/{{category%20+'/'+product.product_id}}">{{product.title}}</a> </h2>

<h5>{{product.price |currency}}</h5>

<p><i>-by:{{product.userName}}</i></p>
</div>
</div>


</div>
</div>

<!-- 2nd Column -->
<div class="col-md-7">
<div class="slide" ui-view></div>
</div>

产品.details.html

<p class="title">{{id}}</p>
<h1>{{product.title}}</h1>
<p>{{product.description}}</p>
<h3>{{product.price|currency}}</h3>

这一切看起来与教程非常相似。我很困惑,感觉很愚蠢。

最佳答案

如果这是您的确切代码,则说明您在模块定​​义和调用 config 之间缺少 .

angular.module('myApp', [...])
.config(['$stateProvider',
function($stateProvider) {
...
}
])

而不是

angular.module('myApp', [...])
config(['$stateProvider',
function($stateProvider) {
...
}
])

这实际上是有道理的,这就是问题所在,因为您的 ui View 无法工作可能是由于缺少状态定义造成的。

关于javascript - UI View 未在 AngularJS 教程中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39431187/

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