angularjs从外部控制器访问指令的链接功能

时间:2015-10-14 18:05:28

标签: javascript angularjs angularjs-directive angularjs-service

我在模板中有两个ng-include,但类似:

<ng-include ng-controller="ctrTable" src="modal.html"></ng-include>

<ng-include ng-controller="ctrButton" src="modal2.html"></ng-include>

我需要刷新控制器ctrTable中的表格表,但按钮位于控制器中,并在控制器tableService中调用服务ctrButton的函数,表格为指令

ctrTable.js

$scope.jqconfig = {
    url:Metronic.getAJAXURL() + "/ajax/getNames",
    datatype: "json",
    colNames:[
              'id',
              'Name'
              ],
    width: null,
    shrinkToFit: false,
    colModel:[
      {name:'name',index:'name',autowidth: true,shrinkToFit: true},{name:'id',index:'id',autowidth: true,shrinkToFit: true}
    ],
    sortname: 'id',
};

ctrButton.js

$scope.refresht = function(){ $tableService.refresh();}

modal.html

<ng-jqgrid config="jqconfig" addnew="true" modeldata="patientdata" gridid="patientgrid" pagerid="patientpager" api="gridapi"></ng-jqgrid>

modal2.html

<input type="button" ng-click="refresht()" />

directive.js

   
Handelbay.directive('ngJqgrid',[ '$window', function ($window) {
return {
    restrict: 'E',
    replace: true,
    scope: {
        config: '=',
        api: '=?',
    },
    link: function (scope, element, attrs) {
        var table, div;
        scope.$watch('config', function (value) {
            table.jqGrid(value);
            scope.api = {
                refresh: function () {
                    table
                        .jqGrid('clearGridData')
                        .jqGrid('setGridParam', { data: scope.modeldata })
                        .trigger('reloadGrid');
                }
            };
        });
    }
}; }]);

TableService.js

Handelbay.factory("$tableService", ['$rootScope','$http',function($rootScope,$http) {

return { refresh: function(){ /* refresh ??? */ } } }]);

0 个答案:

没有答案
相关问题