var app=angular.module('myApp',[]);
app.controller('FCtrl',['$scope','mockFactory',function($scope,mockFactory){
\t $scope.showPerson = function(){
\t \t mockFactory.fetchJson($scope.valueJson)
\t \t .then(function(){
\t \t $scope.persons = mockFactory.array;
\t \t })
\t }
\t $scope.delPerson = function(i){
\t \t mockFactory.delete(i);
\t }
\t $scope.addNamePerson = function() {
\t \t mockFactory.ADD($scope.valueFirst);
\t \t };
\t
\t $scope.showConsolePerson= function(){
\t \t console.log(JSON.stringify(mockFactory.array));
\t }
}]);
app.controller('SCtrl',['$scope','mockFactory',function($scope,mockFactory){
\t $scope.showMovie = function(){
\t \t mockFactory.fetchJson($scope.valueJson)
\t \t .then(function(){
\t \t $scope.movies = mockFactory.array;
\t \t })
\t }
\t $scope.delMovie = function(i){
\t \t mockFactory.delete(i);
\t }
\t $scope.addNameMovie = function() {
\t \t mockFactory.ADD($scope.valueSecond);
\t \t };
\t
\t $scope.showConsoleMovie= function(){
\t \t console.log(JSON.stringify(mockFactory.array));
\t }
}]);
app.controller('TCtrl',['$scope','mockFactory',function($scope,mockFactory){
\t $scope.showPlace = function(){
\t \t mockFactory.fetchJson($scope.valueJson)
\t \t .then(function(){
\t \t $scope.places = mockFactory.array;
\t \t })
\t }
\t $scope.delPlace = function(i){
\t \t mockFactory.delete(i);
\t }
\t $scope.addNamePlace = function() {
\t \t mockFactory.ADD($scope.valueThird);
\t \t };
\t
\t $scope.showConsolePlace= function(){
\t \t console.log(JSON.stringify(mockFactory.array));
\t }
}]);
app.factory('mockFactory',['$http',function($http){
\t \t
\t \t var Precord = {};
\t \t \t Precord.array = [];
\t \t \t Precord.assign = function (value) {
\t \t return $http.get('http://localhost:3000/scripts/' + value + '.json');
\t \t };
\t \t Precord.fetchJson = function(value){
\t \t \t return Precord.assign(value).success(function(response){
\t \t \t \t \t Precord.array = response.value;
\t \t \t \t \t
\t \t \t \t })
\t \t }
\t \t Precord.delete = function(i){
\t \t \t \t \t Precord.array.splice(i,1);
\t \t \t }
\t \t
\t \t \t Precord.ADD = function(value){
\t \t \t \t \t var newName = {
\t \t \t \t \t Name: value
\t \t \t \t };
\t \t \t \t Precord.array.push(newName);
\t \t \t }
\t \t return Precord;
}]);
如何在單個工廠陣列由不同的控制器來訪問,但一次一個,使得在一個控制器的任何更新不能在其他控制器反映? precord.array正在所有的控制器中使用,但我希望它是從其他控制器隔離,而一個控制器正在使用它
保持副本相應的控制器使用 '角,複製()' –
能否請你看上面的腳本和說得清使用angular.copy ...任何幫助,將不勝感激 –