这是我的代码
location: {
address: 'Google Headquarters',
city: 'Mountain View',
province: 'CA'
},
imageUrl: "img/angularjs-logo.png",
sessions: [
{
name: 'Directives Masterclass',
creatorName: 'Bob Smith',
duration: '1 hr',
level: 'Advanced',
abstract: 'In this sesison you will learn the ins and outs of directives!',
upVoteCount: 0
},
图像没有显示,这是conroller.js,我正在使用AngularJS v1.2.10。
<div ng-controller="EventController" style="padding-left:20px; padding-right:20px">
<img ng-src="{{event.imageUrl}}" alt="{{event.name}}" />
也许有不同的方式来展示它,我没有得到错误。我在网上看到了一个完整的网站,它也是这样做的 谁能告诉我我做错了什么?
答案 0 :(得分:0)
您应该拥有的是控制器范围内的事件变量,以使其工作:
你的控制器:
app.controller('MainCtrl', function($scope) {
$scope.event = { location: {
address: 'Google Headquarters',
city: 'Mountain View',
province: 'CA'
},
title: "some title",
imageUrl: "http://plnkr.co/img/plunker.png",
sessions: [
{
name: 'Directives Masterclass',
creatorName: 'Bob Smith',
duration: '1 hr',
level: 'Advanced',
abstract: 'In this sesison you will learn the ins and outs of directives!',
upVoteCount: 0
},
]};
});
你的HTML:
<body ng-controller="MainCtrl">
<p><img ng-src="{{event.imageUrl}}" title="{{event.title}}" /></p>
</body>