【发布时间】:2019-01-16 03:47:53
【问题描述】:
这是我在 StackOverflow 上的第一篇文章,我正在自学 Angular,所以我是初学者,目前很困惑。
我正在使用 Angular 创建一个网页,其中一个页面涉及一个按钮和一个弹出窗口。我想在弹出窗口中放一张图片,但是我在让它工作时遇到了很多麻烦。
步骤和名称属性已成功显示在弹出窗口中,但图像不工作。我尝试让 url 显示为字符串,但这也不起作用。
我也尝试过让 id 属性(它只是一个字符串)出现,但这也不起作用。
我在 html 中的 ctrl.figure 周围只放了一组大括号,因为这至少让我在弹出窗口中得到一个损坏的图片图标,而如果我按照通常的建议使用两个大括号,我什么也得不到.
我在我的本地计算机上托管网站,并使用 Chrome 开发工具,不断收到找不到文件的消息。我已经多次检查了文件路径,看起来还不错。由于我无法让图形的 url 仅显示为字符串,因此我认为问题可能与控制器有关。
任何建议将不胜感激。第一组代码是弹出窗口的html,第二组代码来自控制器。
<!--Overlay div for popup window-->
<div ng-show= "ictrl.showValue" class="instAbsolute col-xs-12 col-md-10 ng-cloak">
<span class= "glyphicon glyphicon-remove pull-right" ng-click = "ictrl.hideDetails()"></span>
<h4 class = "text-muted" >{{ictrl.step}}</h4>
<h1 class = "text-grey">{{ictrl.name}}</h1>
<h1 class = "text-grey">{{ictrl.id}}</h1>
<div ng-bind-html="ictrl.description">
</div>
<img class= "img-responsive" ng-src="{ictrl.figure}" alt="{{ictrl.alt}}">
</div>
</div> <!--end of controller -->
</div> <!--end of app -->
angular.module('instructionsApp', ['ngSanitize']).controller('instructionsCtrl',[
function() {
var self = this;
self.showValue = false;
self.showDetails = function(id) {
for (var i = 0; i < this.steps.length; i++) {
if (self.steps[i].id === id) {
self.name = self.steps[i].name;
self.step = self.steps[i].step;
self.description = self.steps[i].description;
self.showValue = true;
}
}
};
self.hideDetails = function() {
self.showValue = false;
};
self.steps = [{
{
name: "Attach Camera",
id: "S1",
step: "Setup",
description: "<p>There are many ways to attach you camera to your laptop. For digital camera output, we recommend connecting the camera with a wire to the faster firewire port – but the USB port will also work. As an example, for analog camera output you can use an external capture device (such as the Dazzle from Pinnacle) with a 3-port composite connector into the camera and a USB connection on the other end of the cable into the laptop. Also, there are many ways to interface a camera to an internal video capture card. See illustrations below:<\/p>"
}, {
name: "Launch VazztCaster",
id: "S2",
step: "Setup",
figure: "../img/instructionsImages/launchVazztCaster.jpg",
description: "<p>Launch the VazztCaster.exe program on your laptop by clicking on the Vazzt icon (red V) on your desktop. After launch, on the home page of VazztCaster click on the Login Icon (person) and enter the Credentials:<\/p><p>Next Click on the Video Settings Icon (blue camcorder) and enter your choice of <\/p><p> <\/p><p>Note that the VazztCaster will automatically set default values, if possible, in the Video Settings fields based on the camera attached, the IP networks it finds, and the audio equipment attached:<\/p><ul><li>Video Capture Devices<\/li><li>Video Resolution<\/li><li>Video Bandwidth<\/li><li>Aspect Ratio<\/li><li>Audio Capture Device<\/li><li>And other Audio parameters. <\/li><\/ul><p>However, you can manually override these. Click the OK button when you are finished.<\/p><p>Most cameras will automatically provide notification of the various resolutions that the camera can support. VazztCaster can detect this and by examining the bandwidth detected, also automatically, VazztCaster sets default resolution and bandwidth.<\/p><p> <\/p><p> <\/p>",
alt: "Launch VazztCaster",
imageCaption: "After launching VazztCaster, this is what your screen should look like."
}];
}
]);
【问题讨论】:
-
您是否尝试在弹出窗口中打印
{{ictrl.figure}}以查看路径/值是否正确?而不是使用 ng-src? -
也只是硬编码 img src 并确保它在没有角度的情况下工作
-
查看
self.steps中的数据...您没有名为url的属性...请告诉我们这些数据的填充位置(或解释它)。此外,您的 Javascript 声明了一个名为instructionsCtrl的控制器,但在您的 HTML 中您使用的是ictrl。您的问题无法真正回答。 -
我尝试在弹出窗口中将 {{ctrl.figure}} 打印为字符串,但这不起作用。我确实对没有角度的图像 src 进行了硬编码,并且效果很好,所以我相当确定这是正确的路径。 img 的 url 位于名为 figure 的属性下。我在周围的 div 中使用了 ng-controller="instructionsCtrl as ictrl"。这是 GitHub 上 html 文档的链接:github.com/KelseySteele/video-on-the-move-website/blob/master/... 这里是 JS 文档的链接:github.com/KelseySteele/video- on-the-move-website/blob/master/...谢谢!
标签: javascript html angularjs