2016-08-03 4 views
2

저는 AngularJS를 처음 접했고 현재 문제가 있습니다.AngularJS의 문제점

나는

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

내 지시어는 아주이다 ... 내가 지금처럼 HTML 내 요소에 대한 columnmap로 사용하고자하는 내 컨트롤러

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

을에 다음이 광범위한,하지만 난 기본적으로 내 데이터 원본에서 테이블을 구축하고 내 칼럼 맵을 사용하여 원하는 데이터를 매핑, 그 말이 맞는 경우 각 항목에 대한 헤더와 행을 만듭니다.

여기 내 columnmap 빈 문자열을 얻을 위를하는 ...

(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); 
}()); 

내 지시어는 조금 생략합니다. 나는이

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

처럼 내 HTML을 넣어 재산 columnmap에 "="를 내 분리 범위를 변경하는 경우

지금, 모두 괜찮습니다. 나는 이것보다 조금 더 캡슐화하려고 노력하고있다.

도움을 주시면 감사하겠습니다.

답변

1

내 문제는 필자의 칼럼 맵을 객체로 파싱하지 않는다는 것이 었습니다. 일단 내가 그렇게하고 유효한 json을 제공하면 내 솔루션이 효과를 발휘했습니다.