angular.js - angular指令通過"="不能獲取數(shù)據(jù)
問題描述
也不能說不能獲取,但是不知道出了什么問題, 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));//這樣應(yīng)該能取得的。 console.log('---------directive---------');}
因為數(shù)據(jù)的異步問題
回答2:你這個數(shù)據(jù)是從后臺獲取的吧。使用$watch監(jiān)聽一下,你就知道了,我也認為是異步的問題。
相關(guān)文章:
1. python - Django 表單問題?2. 索引 - 請教下Mysql大數(shù)據(jù)量的聯(lián)合查詢3. 如何修改phpstudy的phpmyadmin放到其他地方4. 爬蟲圖片 - 關(guān)于Python 爬蟲的問題5. 關(guān)于Mysql聯(lián)合查詢6. pip安裝提示Twisted錯誤問題(Python3.6.4安裝Twisted錯誤)7. mysql - 類似于之類的通知系統(tǒng)如何設(shè)計數(shù)據(jù)庫8. python 計算兩個時間相差的分鐘數(shù),超過一天時計算不對9. 人工智能 - python 機器學(xué)習(xí) 醫(yī)療數(shù)據(jù) 怎么學(xué)10. javascript - 百度搜索網(wǎng)站,如何讓搜索結(jié)果顯示一張圖片加上一段描述,如圖;求教
