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---------');}
因?yàn)閿?shù)據(jù)的異步問題
回答2:你這個數(shù)據(jù)是從后臺獲取的吧。使用$watch監(jiān)聽一下,你就知道了,我也認(rèn)為是異步的問題。
相關(guān)文章:
1. angular.js - 關(guān)于$apply()2. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。3. MySQL數(shù)據(jù)庫中文亂碼的原因4. dockerfile - 我用docker build的時候出現(xiàn)下邊問題 麻煩幫我看一下5. nignx - docker內(nèi)nginx 80端口被占用6. android-studio - Android Studio 運(yùn)行項(xiàng)目的時候一堆警告,跑步起來!?7. dockerfile - [docker build image失敗- npm install]8. angular.js - Ionic 集成crosswalk后生成的apk在android4.4.2上安裝失敗???9. mysql - 新浪微博中的關(guān)注功能是如何設(shè)計(jì)表結(jié)構(gòu)的?10. 如何解決Centos下Docker服務(wù)啟動無響應(yīng),且輸入docker命令無響應(yīng)?
