0

У меня есть угловой контроллер и директивуAngularJS: обновление родительской области из директивы

Контроллер

app.controller('gridController',['$scope',function($scope){      
        $scope.btns=false; 
        $scope.details_tab=false; 
        $scope.currentid={id:''}; 
        $scope.setId=function(id){ 
         $scope.currentid=id; 
        }; 
}]); 

Директива

 .directive('jqGrid',function(){ 

        return{ 
         restrict: 'E', 
         //require: 'ngModel', 

         link:function(scope, element, attrs){ 
          jQuery("#jqgrid").jqGrid({ 
           data : scope.jqgrid_data, 
           datatype : "local", 
           height : 'auto', 
           colNames : ['case', 'Name', 'Assigned Date'], 
           colModel : [ 
            { name : 'act', index:'act', sortable:false }, 
            { name : 'id', index : 'id' }, 
            { name : 'date', index : 'date', editable : true }, 
            { name : 'name', index : 'name', editable : true }, 
            { name : 'amount', index : 'amount', align : "right", editable : true }, 
            { name : 'tax', index : 'tax', align : "right", editable : true }, 
            { name : 'total', index : 'total', align : "right", editable : true }, 
            { name : 'note', index : 'note', sortable : false, editable : true }], 
           rowNum : 10, 
           rowList : [10, 20, 30], 
           pager : '#pjqgrid', 
           sortname : 'id', 
           toolbarfilter: true, 
           viewrecords : true, 
           sortorder : "asc", 
           gridComplete: function(){ 

           }, 
           multiselect : true, 
           autowidth : true, 
           onSelectRow : function (rowid, status) { 
               scope.btns=true; 
               scope.details_tab=true; 
               scope.currentid=''; 
               } 

     })}}); 

HTML:

  <jq-grid jqdata="jqgrid_data"> 
       <table id="jqgrid" ></table> 
      </jq-grid> 

Здесь в директиве я хочу подняться date переменная в области Она обновляется в локальной области, но не в области контроллера. Как я могу обновить область напрямую?

ответ

0

я исправила эту проблему с

  scope.$apply(); 
0

Добавить scope: true в возвращаемый объект.

.directive('jqGrid',function(){ 
    return { 
     restrict: 'E', 
     scope: true, 
     ... 
0
app.controller('gridController',['$scope',function($scope){      
        $scope.btns=false; 
        $scope.details_tab=false; 
        $scope.currentid={id:''}; 
        $scope.setId=function(id){ 
         $scope.currentid.id=id; // change 
        }; 
}]); 

    onSelectRow : function (rowid, status) { 
               scope.btns=true; 
               scope.details_tab=true; 
               scope.currentid.id=rowid; 
               }