通过 AngularJs 创建的对象未出现在网页上

Object created via AngularJs is not appearing on web page

这是我的代码。请告诉我我哪里错了。当我加载网页时,对象盘没有显示。该网页仅保持空白。我正在使用 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 instead. See 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 转换为控制器 JSFiddle

这里的 plnkr 工作得很好

http://plnkr.co/edit/IgjAHFOP27qhmEp75yNE?p=preview

<div class="container">
    <div class="row info" ng-controller="demo">
        <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>