2017-07-07 82 views
-2

Plunker在這裏: - http://plnkr.co/edit/JaEi7ftnokYhdvBn4fRh?p=preview 我已經發出數據,並且它在data.name下的$ on()中可用。

但是,我無法在UI中使用{{dumbevent1_name}}顯示$ scope.dumbevent1_name 我在做什麼錯了?

代碼: -

//代碼放在這裏

angular.module('myapp', []) 
.controller('mycontroller', mycontroller) 
.component('semantic3', { // semantic3 
    restrict: 'E', 
    transclude: true, 
    template: `<h6> imsemantic3</h6> <div ng-transclude></div> 
       `, 
    controller: semantic3Controller,   
    }) 
.component('semantic2', { // semantic2 
    scope: {}, 
    restrict: 'E', 
    transclude: true, 
    template: `<h6> imsemantic2</h6> <div ng-transclude></div> 
       `, 
    }) 
.component('semantic1', { // semantic1 
    scope: {}, 
    restrict: 'E', 
    transclude: true, 
    template: `<h6> imsemantic1</h6> <div ng-transclude></div> 
       `, 
    }) 
.component('dumbCompDisplayNames', { 
    scope:true, 
    restrict: 'E', 
    template: `<h6>h6dumb1</h6> {{$ctrl.names}}`, 
    bindings:{ 
     names : '<' //one-way data binding 
    }, 
    controller: dumbController, 
}); 


function semantic3Controller($scope, $element, $attrs){ 
    var self = $scope; 
    $scope.$on('dumbevent1', function(event, data){ 
    console.log(data.name); //works. received. 
    self.dname = data.name; 
    $scope.dumbevent1_name = data.name; //works 
    // console.log($scope.dumbevent1_name); //works 
    // capturename(data); //works 
    }); 
    // console.log($scope.dumbevent1_name); //doesnt work. 
    // function capturename(x){ 
    // $scope.dumbevent1_name = x.name; 
    // console.log($scope.dumbevent1_name); //works 
    // } 

} 


function dumbController($scope, $element, $attrs){ 
    // console.log($scope); //works. these r NOT positional injection 
    // console.log($element); 
    // console.log($attrs); 

    $scope.$emit('dumbevent1', {name: 'namedumb1'}); 
} 

// main controller 
function mycontroller(){ 
    console.log('i am mycontroller'); 
} 
+0

的例子是與您選擇的命名非常令人迷惑:somecrap,imsemantic3,imsemantic2,imsemantic1,h6dumb1 –

+0

dumbCompDisplayNames是其發出的事件,一個愚蠢的組成部分,我已經抓獲,在裏面$智能組件(名爲semantic3)() 。但是,我無法在ui上顯示data.name。 – Plankton

+0

atleast發表評論你爲什麼低調?什麼問題 ?? – Plankton

回答

0

浪費在評論的時間反覆是值得不知何故?如果沒有時間看看這個重頭戲,不要浪費時間評論。就像我說的,我解決了這個問題。