angular.js - AngularJS 中如何給一個自定義指令 directive 傳遞一個對象類型的參數(shù)?
問題描述
我想寫一個自定義指令,根據(jù)外部傳進來的數(shù)組,在頁面上生成一個表格。我該怎么做?angularjs的自定義指令是否只能接收字符串參數(shù)?哪位大神能幫幫忙,謝謝!
問題解答
回答1:可以給你個簡單示例:jsFiddle
<p ng-controller='DemoCtrl'> <ng-table data='list'></ng-table></p>
var demo = angular.module(’demo’, []);demo.directive(’ngTable’, function(){ return {restrict: ’E’,scope: { data: ’=’},link: function($scope, element, attrs){ },template: ’<table><tr ng-repeat='item in data'><td>{{ item.id }}</td><td>{{ item.name }}</td></tr></table>’ };});demo.controller(’DemoCtrl’, function($scope){ $scope.list = [{ id: 123, name: ’Hello World’},{ id: 234, name: ’Fucking world’},{ id: 345, name: ’What did you say?’} ];});
至于是不是“只能傳字符串”,你需要看明白文檔先:

文檔地址:scope
相關(guān)文章:
1. javascript - immutable配合react提升性能?2. 如何設(shè)置一個無限循環(huán)并打破它。(Java線程)3. python小白 自學(xué)看書遇到看不懂的地方4. javascript - sublime快鍵鍵問題5. macos - 如何徹底刪除mac自帶的apache和php6. docker 17.03 怎么配置 registry mirror ?7. shell - mysql更新錯誤8. DADB.class.php文件的代碼怎么寫9. php對mysql提取數(shù)據(jù)那種速度更快10. 實現(xiàn)bing搜索工具urlAPI提交

網(wǎng)公網(wǎng)安備