我是 angularjs 的新手,我正在学习指令,并且我正在尝试将值传递给指令,但事情不起作用。
html
<genericsearch objectType="tei_org" organisationSearch="organisationSearchEvent"></genericsearch>
指令
directive('genericsearch', [function () {
return {
restrict: 'E',
replace: true,
scope: {
objectType : '=',
},
controller: ['$scope','$element','$rootScope','SearchOrg','MapOrgs','$routeParams','DelOrgs','GetTemplateGroups','FetchOrgs', function($scope,$element,$rootScope,SearchOrg,MapOrgs,$routeParams,DelOrgs,GetTemplateGroups,FetchOrgs){
$scope.getOrgs = function(objectType, event) {
if(event.keyCode != 13){
//$scope.Participants(data);
$scope.organisationSearchEvent(objectType);
}
}
$scope.organisationSearchEvent = function(filter,objectType){
SearchOrg().fetch({'filter':filter, 'searchType':objectType}).$promise.then(
function(value){
$scope.orgList = value.data;
},
function(err){
});
}
}],
templateUrl : TAPPLENT_CONFIG.HTML_ENDPOINT[0]+'home/search.html'
}
}])
最佳答案
您似乎误解了 $scope 和/或如何将值传递给函数。
Controller 的 $scope 有一个属性 objectType
。您不需要将其作为参数添加到 Controller 内的函数中。
您只需通过 $scope.objectType
访问它即可。
例如
$scope.organisationSearchEvent = function(filter){
SearchOrg().fetch({'filter':filter, 'searchType':$scope.objectType}).$promise.then(
function(value){
$scope.orgList = value.data;
},
function(err){
});
}
关于javascript - 将变量的值传递给 angularjs 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29824815/