这是我的代码:
.directive('Search', function($templateRequest, $compile) {
return {
link: function(scope, element, $scope){
$templateRequest('/js/angularjs/search.html').then(function(html){
var template = angular.element(html);
element.append(template);
$compile(template)(scope);
$('#multipleSelect').multipleSelect({
test: console.log($scope),
onClick: function(view, scope) {
//view.checked ? scope.searchByTitle.multi.push(view.value) : scope.searchByTitle.multi.remove(view.value);
console.log('scope:');
console.log($scope);
}
});
});
}
};
});
我正在使用这个插件: http://wenzhixin.net.cn/p/multiple-select/docs/
我想在更改多个选择值之一后实现这一目标,我也想将某些东西插入 AngularJS 范围(主要使用 onClick 事件)。但作用域在 jQuery 函数内部不可访问...
如果您对此有任何解决方法的想法,我也想听听:P
最佳答案
onClick: function(view, scope) {
var scope = angular.element($("#multipleSelect")).scope();
view.checked ? scope.searchByTitle.multi.push(view.value) : scope.searchByTitle.multi.remove(view.value);
}
这就是我设法找到的解决方案。它有效:)
关于javascript - 是否可以在 jQuery 事件中更改 Angular 范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37110635/