2016-08-03 56 views
2

我對AngularJS相當陌生,並且遇到了當前的問題。AngularJS的問題

我有我的控制器

//Define the programs list table columns 
    $scope.programListColumns = "[{ Name: 'Name'},{ Status: 'Status'},{ CreatedByUserName: 'Created By'},{ ModifiedDate: 'Modified'},{ ModifiedByUserName: 'Modified By'}]"; 

下面我想在HTML中使用這個作爲columnmap我的元素,像這樣......

<table-helper datasource="programsList" columnmap="{{programListColumns}}"></table-helper> 

我的指令是很廣泛的,但我基本上從我的數據源建立一個表,並使用我的柱狀圖映射我想要的數據,如果有意義的話,爲每個項目創建標題和行。

這裏是我的指令簡稱有點...

(function(){ 
var app = angular.module("MdfAngularApp"); 
var tableHelper = function() { 
    //Initiate variables for directive 
    //var template = '<div class="tableHelper"></div>', 
    var link = function(scope, element, attrs) { 
      var headerCols = [], 
       tableStart = '<table>', 
       tableEnd = '</table>', 
       table = '', 
       visibleProps = [], 
       sortCol = null, 
       sortDir = 1; 

      //Watch the datasource for changes. 
      scope.$watchCollection('datasource', render); 

      ... Functions go here ... 
return { 
     restrict: 'E', 
     replace: true, 
     scope: { 
      columnmap: '@', 
      datasource: '=' 
     }, 
     link: link, 
    } 
}; 

app.directive('tableHelper', tableHelper); 
}()); 

做上述我得到一個空字符串作爲我的columnmap。

現在,如果我把我的HTML這樣

<table-helper datasource="programsList" columnmap="[{ Name: 'Name'},{ Status: 'Status'},{ CreatedByUserName: 'Created By'},{ ModifiedDate: 'Modified'},{ ModifiedByUserName: 'Modified By'}]"></table-helper> 

和改變我的分離範圍columnmap屬性爲「=」,一切都很好。我只是想比這更封裝一點。

任何幫助將不勝感激。

回答

1

我的問題是,我沒有解析我的柱狀圖作爲對象。一旦我做到了這一點,並提供有效的JSON,我的解決方案工作。