gpt4 book ai didi

javascript - 通过 AngularJs 创建的对象没有出现在网页上

转载 作者:行者123 更新时间:2023-11-27 22:51:15 25 4
gpt4 key购买 nike

这是我的代码。请告诉我我哪里错了。当我加载网页时,不显示目标盘。该网页仅保持空白。我正在使用 AngularJs。

<!DOCTYPE html>
<html lang="en" ng-app>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="hk.css">
<link rel="stylesheet" href="font-awesome-4.6.3/css/font-awesome.min.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-social.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<div class="container">
<div class="row info" ng-init="dish={name:'Uthapizza',
image:'uthapizza.png',
category:'mains',
label:'hot',
price:'4.99'
description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.',
comment:''}">
<div class="col-md-12">
<div class="media">
<div class="media-left media-middle">
<a href="#"><img class="img-thumbnail media-object" ng-src={{dish.image}}></a>
</div>
<div class="media-body">
<h2 class="media-heading">{{dish.name}}<span class="label label-dangerous label-xs">{{dish.label}}</span><span class="badge">{{dish.price}}</span></h2>
<p>{{dish.description}}</p>
</div>
</div>
</div>
</div>
</div>

最佳答案

ng-init json 对象中缺少 ,:

angular.js:13424 Error: [$parse:syntax] Syntax Error: Token 'description' is unexpected, expecting [}] at column 317 of the expression [dish={name:'Uthapizza', image:'uthapizza.png',

在描述前添加,

price:'4.99',
description:'A unique combination of ....
<小时/>

旁注:

使用 ng-init 可以用于测试目的,但稍后考虑使用 controller反而。请参阅AngularJS ng-init docs :

This directive can be abused to add unnecessary amounts of logic into your templates. There are only a few appropriate uses of ngInit, such as for aliasing special properties of ngRepeat, as seen in the demo below; and for injecting data via server side scripting. Besides these few cases, you should use controllers rather than ngInit to initialize values on a scope.

<小时/>

在此处查看您的 ngInit 转换为 Controller JSFiddle

关于javascript - 通过 AngularJs 创建的对象没有出现在网页上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38037428/

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