私は2ページあります。最初はItemMenuPage
秒ですCartPage
です。アイテム名をクリックするとCartPage
に移動する必要がありますが、そのアイテム名を表示する必要がありますCartPage
。別のページにクリックしたときに名前フィールドを渡す方法
MenuController
.controller('FoodCtrl', function($scope,$state,mySharedService) {
$scope.addProductItem=function(product){
var itemName=product.itemName;
mySharedService.setData(product);
$state.go('app.produce');
}
});
CartController
.controller('ProduceSaveController', ['$scope','mySharedService',
function(scope,mySharedService){
scope.$on('handleBroadcast',function(){
scope.itemName=mySharedService.itemName;
})
service.js通常
.factory('mySharedService',function($rootScope){
var sharedService={};
sharedService.itemName='';
sharedService.setData=function(product){
this.itemName=product;
this.broadcastItem();
};
sharedService.broadcastItem=function(){
$rootScope.$broadcast('handleBroadcast');
};
return sharedService;
})
私がこの$ scope.addProductItem =機能(製品){ VAR itemNameに= product.itemNameのように作成された私のために働いていません。 mySharedService.setData(product); $ state.go( 'app.produce'); } – umapathi
完全なコードではありません。選択した保管場所からアイテムを保管して取得するコードを記述する必要があります。 – AndrewR
新しい質問を開始することをお勧めします。これは、この問題が解決し、関連するすべてのコードが含まれているためです。 – AndrewR