嗨,我在angularjs工作。我在指令中遇到了一个问题。
我已经设置链接scope.user.name="amin shah"
/点击事件 ,并希望访问该控制器中,这怎么可能?Angularjs指令的指令,并访问设定范围VAR在控制器
var dataSourceDirective = angular.module('mydirective', []);
dataSourceDirective.directive('dir', function() {
return {
restrict: 'C',
scope: true,
link: function ($scope, element, attrs) {
element.bind('click', function() {
$scope.user.name ="amin shah";
$scope.$apply();
$('.sourceType_panel').hide();
$('#sourceType_1_panel').show();
});
}
}
});
控制器代码
$scope.demo = function() {
console.log($scope.user);`
},