2
嗨,我想知道什么是更好的性能方面。 比方说,我有这样的工厂,广播的东西:
angular.module('core.foo')
.factory('Foo',
['$rootScope',
function FooFactory($rootScope) {
$rootScope.$broadcast('bar', baz);
}
]
);
而且有地方的组件(或他们中的很多),监听该事件。什么会更好?
使用$ rootScope $上:。
angular.module('foo').component('foo', {
templateUrl: 'foo.html',
controller: ['$rootScope',
function FooController($rootScope) {
$rootScope.$on('bar', function(event, data){
// use the data
});
}]
});
或$范围$于:
angular.module('foo').component('foo', {
templateUrl: 'foo.html',
controller: ['$scope',
function FooController($scope) {
$scope.$on('bar', function(event, data){
// use the data
});
}]
});
两个会的工作,我只是好奇。