如何在我的例子中设置我的Angular指令
How to setup my Angular directive in my case?
我正在尝试创建一个具有隔离作用域的指令。
我angular.module('myApp').directive('itemCollection',
['$cookies',
function($cookies) {
return {
restrict: 'E',
scope: {
items: '='
},
link: function(scope) {
console.log(scope.items)
console.log(items)
--> both console.log show undefined
}
};
}
]);
Html <item-collection items="item1"></item-collection>
我似乎不能得到'item1'
在我的指令,它是未定义的。我不知道我错过了什么。有人能帮我一下吗?谢谢!
item1
是否异步来?如果是,你需要在你的指令中设置一个手表,并在它可用时尽快处理。
return {
restrict: 'E',
scope: {
items: '='
},
link: function(scope) {
console.log(scope.items)
console.log(items)
--> both console.log show undefined
scope.$watch(
function() { return scope.items; },
function(newValue) {
if (newValue != null) {
console.log('not null:' + newValue);
}
else {
console.log('still null, skip');
}
}
);
}
};
相关文章:
- 使用JAVASCRIPT转换货币.可以't通过我的函数设置转换后的输入文本字段的值
- 我可以设置HTML5文件上传的视频长度限制吗
- 我如何设置HTTP头“;访问控制允许起源”;用于来自thttpd web服务器的HTTP响应
- 如何在我的情况下设置日期格式
- angular如何在我的情况下设置服务
- 如何在我的情况下设置类名
- AJAX 请求没有在我的 React 组件中设置 this.state.data
- 如何创建一个组件,我可以设置在 Angular 2 中的属性中获取 URL 数据
- 为什么为我的数据表设置类没有任何作用
- 如何配置js美化程序设置来实际美化我的HTML/Javascript代码
- 设置doctype会破坏我的css和javascript
- 我可以设置这个吗'某事'在该服务中动态创建的嵌套对象中的服务?(可能是范围问题)
- 如何将查询参数设置为我的所有路线,当它改变时-在恩伯
- 为什么ajax回调在我的本地变量中设置undefined
- d3.js-当鼠标悬停在SVG容器上的这些元素上时,我如何设置光标
- 我的设置超时不会自动提交我的按钮
- 我的设置超时无法正常工作
- 为什么我的设置函数之间的超时不起作用
- VB 2013:自动登录从我的.设置问题
- 为什么我的设置状态不起作用