gpt4 book ai didi

javascript - Angular : my isolated attribute not binding in simple directive

转载 作者:行者123 更新时间:2023-12-02 17:46:27 24 4
gpt4 key购买 nike

我正在使用this tutorial了解如何使用具有隔离范围的指令来显示图像。我缺少什么来绑定(bind)属性?在我的IDE中,我可以输出图像,但指令不起作用。 fiddle 没有显示任何内容:-(

fiddle :http://jsfiddle.net/gogirl/Stm3j/

这是在我的程序中输出的:

 output:{{photo.url}}
<img ng-src='http://www.w3schools.com/js/pic_bulboff.gif' />

这不输出:

 <my-d photo-src={{photo.url}} ></my-d>

最佳答案

您的 jsfiddle 配置中有残留数据

这是我为使其发挥作用所做的事情

  1. 移除外部资源,因为您将 Angular 1.0.1 与 Angular 1.2.1 一起使用
  2. 在选项面板中删除 body 标记 myModule
  3. 去掉 undefined variable app的调用,用angular.module查询

jsfiddle updated here

// My Main Application File
angular.module('myApp', ['myDirectives']);

// My Directives File
angular.module('myDirectives', []);

// Controller One File
angular.module('myDirectives', []).directive('myD', function () {
return {
restrict: 'E',
template: '<figure> <img ng-src="{{photoSrc}}"/> </figure>',
replace: true,
// pass these two names from attrs into the template scope
scope: {
photoSrc: '@'
}
}
})

关于javascript - Angular : my isolated attribute not binding in simple directive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21710109/

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