嗨,我在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);`
},