angular.js - angular指令通过"="不能获取数据
问题描述
也不能说不能获取,但是不知道出了什么问题, scope 可以看到, 但是通过属性访问却访问不到
具体看下面代码和图片
html 中
<ul widget-paginate='vm.activities'></ul>
directive.js 中
var directive = { scope:{paginate : ’=widgetPaginate’ }, link : link}function link(scope, ele, attrs){ console.log(scope); console.log('---------directive---------'); console.log(scope.paginate.data); console.log('---------directive---------');}



问题解答
回答1:var directive = { scope:{paginate : ’=widgetPaginate’ }, link : link}function link(scope, ele, attrs){ console.log(scope); console.log('---------directive---------'); $timeout(console.log(scope.paginate.data));//这样应该能取得的。 console.log('---------directive---------');}
因为数据的异步问题
回答2:你这个数据是从后台获取的吧。使用$watch监听一下,你就知道了,我也认为是异步的问题。
相关文章:
1. javascript - 初学angularJS+express,路由路径中/转换成%2F,导致路径失效,求原因?2. PHP类中的$this3. html - 急求,能否用flex或者高端点的CSS来布局这个图呢?不想用浮动或定位了4. html5 - 只用CSS如何实现input框的宽度随框里输入的内容长短自动适应?5. boot2docker无法启动6. javascript - 关于jsp中嵌入js代码的问题7. javascript - 百度坐标,返回目标附近有哪些坐标8. javascript - 前端如何实现这种美图秀秀效果9. Python操作sqlserver是异步的吗?10. python - 抓取天猫详情页里面的月销量,反爬非常厉害

网公网安备