在使用angular JS制作带有JS的移动应用程序时,在第一页上使用select选项传递下一页的数据时遇到问题。对于下一页无法显示任何空白屏幕。有关详细信息,请查看my plunker以查找我的脚本中的错误。 它来自我的plunker的“script.js”:
angular.module('ex', [
'ngRoute',
'ngStorage',
])
.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when('/view1', {
templateUrl: 'view1.html',
controller: 'View1Ctrl',
})
.when('/view2', {
templateUrl: 'view2.html',
controller: 'View2Ctrl',
})
.otherwise('/view1');
}
])
.controller('View1Ctrl', ['$scope', '$location', '$localStorage',
function($scope, $location, $localStorage) {
$scope.view1 = $localStorage.view1 = {
text: '',
number: 0,
type: '',
discount: '',
};
$scope.producttype = [{
product: "A",
value: 7900000,
discount1: 5612,
discount2: 79000
}, {
product: "B",
value: 10200000,
discount1: 5612,
discount2: 79000
}, {
product: "C",
value: 11000000,
discount1: 5612,
discount2: 79000
}, {
product: "D",
value: 7300000,
discount1: 5612,
discount2: 79000
}, {
product: "E",
value: 10000000,
discount1: 5612,
potongan2: 79000
}, {
product: "F",
value: 11200000,
discount1: 5612,
discount2: 79000
}, ];
$scope.submit = function() {
$location.path('/view2');
};
}
])
.controller('View2Ctrl', ['$scope', '$localStorage',
function($scope, $localStorage) {
// I want show discount list based on "Discount Type" like "discount1" for "good" and "discount2" for "decent"
if (view1.type == "Good") {
view1.selection = view1.type.discount1;
console.log(view1.discount);
} else {
view1.selection = view1.type.discount2;
console.log(view1.discount);
}
$scope.view1 = $localStorage.view1;
}
])
除此之外,我怎样才能在下一页(view2.html)中根据“折扣类型”显示折扣清单,例如“discount1”为“good”和“discount2”为“decent”?
提前多多谢谢你。
答案 0 :(得分:1)
请参阅此处更新的plunk
Mailny,我曾参加过将保存提交到localstorage的活动,
$scope.submit = function() {
$localStorage.view1 = $scope.view1;
$location.path('/view2');
};
并在view2中更改了几个东西以指向$ scope.view1
if ($scope.view1.type == "Good") {
$scope.view1.selection = $scope.view1.type.discount1;
console.log($scope.view1.discount);
} else {
$scope.view1.selection = $scope.view1.type.discount2;
console.log($scope.view1.discount);
}