-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');
}
的例子是与您选择的命名非常令人迷惑:somecrap,imsemantic3,imsemantic2,imsemantic1,h6dumb1 –
dumbCompDisplayNames是其发出的事件,一个愚蠢的组成部分,我已经抓获,在里面$智能组件(名为semantic3)() 。但是,我无法在ui上显示data.name。 – Plankton
atleast发表评论你为什么低调?什么问题 ?? – Plankton