Javascript 来自外部控制器的指令的angularjs访问链接功能
我在模板中有两个Javascript 来自外部控制器的指令的angularjs访问链接功能,javascript,angularjs,angularjs-directive,angularjs-service,Javascript,Angularjs,Angularjs Directive,Angularjs Service,我在模板中有两个ng include,但类似: 我需要刷新控制器ctrTable中的表,但按钮在控制器中,并调用控制器ctrButton中的服务tableService函数,该表是一个指令 ctrTable.js Handelbay.directive('ngJqgrid',[ '$window', function ($window) { return { restrict: 'E', replace: true, scope: { config:
ng include
,但类似:
我需要刷新控制器ctrTable
中的表,但按钮在控制器中,并调用控制器ctrButton
中的服务tableService
函数,该表是一个指令
ctrTable.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');
}
};
});
}
}; }]);
Handelbay.factory("$tableService", ['$rootScope','$http',function($rootScope,$http) {
return { refresh: function(){ /* refresh ??? */ } } }]);
$scope.jqconfig={
url:Metronic.getAJAXURL()+“/ajax/getNames”,
数据类型:“json”,
姓名:[
“id”,
“姓名”
],
宽度:空,
shrinkToFit:错,
colModel:[
{name:'name',index:'name',autowidth:true,shrinkToFit:true},{name:'id',index:'id',autowidth:true,shrinkToFit:true}
],
sortname:'id',
};
ctrButton.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');
}
};
});
}
}; }]);
Handelbay.factory("$tableService", ['$rootScope','$http',function($rootScope,$http) {
return { refresh: function(){ /* refresh ??? */ } } }]);
$scope.refresht=function(){$tableService.refresh();}
modal.html
<ng-jqgrid config="jqconfig" addnew="true" modeldata="patientdata" gridid="patientgrid" pagerid="patientpager" api="gridapi"></ng-jqgrid>
<input type="button" ng-click="refresht()" />
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.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');
}
};
});
}
}; }]);
Handelbay.factory("$tableService", ['$rootScope','$http',function($rootScope,$http) {
return { refresh: function(){ /* refresh ??? */ } } }]);
那些是情态动词还是部分动词?您可以将其中一个的代码包含到另一个中(即modal.html中包含modal2的ng include),并通过DOM访问它。要通过JS访问它,您应该使用指令/组件绑定(您在指令中看到的“@”、“=”、“&”等)是modals还是partials?您可以将其中一个的代码包含到另一个中(即modal.html中包含modal2的ng include),并通过DOM访问它。要通过JS访问它,您应该使用指令/组件绑定(您在指令中看到的“@”、“=”、“&”等)