相关疑难解决方法(0)

AngularJS:指令无法访问隔离范围对象

我试图在我的指令中使用Isolate范围设置一些默认值.基本上,我需要在绑定指令时使用scope对象进行一些DOM操作.以下是我的代码:

控制器:

angular.module('ctrl').controller('TempCtrl', function($scope, $location, $window, $timeout, RestService, CommonSerivce) {

$scope.showAppEditWindow = function() {
    //Binding the directive isolate scope objects with parent scope objects
    $scope.asAppObj = $scope.appObj;
    $scope.asAppSubs = $scope.appSubscriptions;

    //Making Initial Settings
    CommonSerivce.broadcastFunction('doDirectiveBroadcast', "");
};
Run Code Online (Sandbox Code Playgroud)

服务:

angular.module('Services').factory('CommonSerivce', function ($rootScope) {
return {       
    broadcastFunction: function(listener, args) {
        $rootScope.$broadcast(listener, args);
    }
};
Run Code Online (Sandbox Code Playgroud)

指示:

angular.module('directives').directive('tempDirective', function() {
return {
    restrict : 'E',
    scope:{
        appObj:'=asAppObj',
        appSubs: '=asAppSubs'
    },
    link : function(scope, element, attrs) {},
    controller : function ($scope,Services,CommonSerivce) {         
        //Broadcast Listener 
        $scope.$on('doDirectiveBroadcast', function …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-directive angularjs-service angularjs-scope

9
推荐指数
1
解决办法
2万
查看次数