'use strict'; angular.module('warehost') .controller('MenuWebCtrl',function(session,config,alert,$scope,$rootScope,$http,$stateParams){ alert.set({}); $scope.list = {}; $scope.website = {}; function load(){ $http.get(config.api+'/web/involve').then(function(res){ session.set(res); alert.set(res); $scope.list = res.data.data; for(var key in res.data.data){ var item = res.data.data[key]; if(item.website.ID === $stateParams.websiteid){ $scope.website = item.website; } } }); } load(); $rootScope.$on('warehost.web.website.update',load); $scope.add = function(){ $http.post(config.api+'/web/website',{name:window.prompt('Name:')}).then(function(res){ session.set(res); $rootScope.$broadcast('warehost.web.website.update'); }); }; });