我最近改变了我的工厂FROM
app.factory('controllerComm', function($rootScope)
{
var showVforum = {};
showVforum.result = false;
showVforum.prepBroadcast = function(val)
{
this.result = val;
this.broadcastVal();
}
showVforum.broadcastVal = function()
{
$rootScope.$broadcast('toggleVforum')
}
return showVforum;
});
到这个
app.factory('controllerComm', ['$rootScope', function($rootScope)
{
var showVforum = {};
showVforum.result = false;
showVforum.prepBroadcast = function(val)
{
this.result = val;
this.broadcastVal();
}
showVforum.broadcastVal = function()
{
$rootScope.$broadcast('toggleVforum')
}
return showVforum;
}]);
我这样做是出于 JS 缩小的原因。在我改变它之前,我在我的一个控制器中工作:
$scope.$on('toggleVforum', function()
{
$scope.isVisible = controllerComm.result;
$('#vforum').verticalAlign();
player.play();
});
controllerComm.result
自从我换了工厂后,现在又回来undefined
了,我不知道为什么。有任何想法吗?
编辑
错误:
TypeError: Object function e(e,f,i){var j=c.defer(),k=j.promise,l=y(i)&&!i,f=a.defer(function(){try{j.resolve(e())}catch(a){j.reject(a),d(a)}l||b.$apply()},f),i=function(){delete g[k.$$timeoutId]};
k.$$timeoutId=f;g[f]=j;k.then(i,i);return k} has no method 'prepBroadcast'
at Object.$scope.hideVforum (http://localhost/aventos/resources/js/aventos.js:645:20)
at http://localhost/aventos/resources/js/angular.min.js:72:251
at http://localhost/aventos/resources/js/angular.min.js:144:140
at Object.e.$eval (http://localhost/aventos/resources/js/angular.min.js:88:347)
at Object.e.$apply (http://localhost/aventos/resources/js/angular.min.js:88:454)
at HTMLButtonElement.<anonymous> (http://localhost/aventos/resources/js/angular.min.js:144:122)
at HTMLButtonElement.x.event.dispatch (http://localhost/aventos/resources/js/jquery-1.10.2.min.js:5:14129)
at HTMLButtonElement.v.handle (http://localhost/aventos/resources/js/jquery-1.10.2.min.js:5:10866)