2017-04-17 91 views
0

引导保持它短后反应迟钝的功能,它的一个单页应用程序,以便的index.php首先装载有缺省模板的URL和控制器。当我点击一个按钮并移动到一个新路线(新的模板UI和控制器)时,该页面中没有任何工作,单击取消按钮不会弹出警告或将我重定向到主页面。角路由,当前路线按钮/从缺省路由

基本上 主页:列表销售网页(网址#1控制器#1) - >点击新增销售 - >新增销售页面(网址#2控制器2)>按钮不起作用

路由

var app = angular.module("phpApp", ["ngRoute"]); 
app.config(['$routeProvider','$locationProvider',function ($routeProvider, $locationProvider) { 
$routeProvider.when("/",{ 
    templateUrl:"view-list.php", controller: "listController" 
}) 
    .when("/add", { 
    templateUrl:"view-details.php", controller:"addController" 
}) 
.when("/:index",{ 
    templateUrl:"view-details.php", controller:"editController" 
}) 
.otherwise({ 
    redirectTo:"/" 
}); 
}]); 

默认templateURL(假装主索引页只有1个按钮,这是 “添加销售”)

<div class="form-group"> 
    <button data-ng-click="addSales()" class="btn btn-primary">Add Sales</button> 
</div> 

默认控制器

app.controller('listController', ['$scope', '$location','$routeParams', 'salesService', function($scope, $location, $routeParams, salesService){ 
$scope.data = salesService.getSales(); 

$scope.addSales = function(){ 
    $location.path('/add'); 
}; 

$scope.editSales = function(x) 
{ 
    $location.path("/" + x); 
}; 

$scope.delSales = function(x) 
{ 
    if (confirm('Are you sure to delete?')) 
    { 
     alert("deleted item asdasd"); 
     //var index = $scope.bdays.indexOf(item); 
     //$scope.bdays.splice(index, 1); 
    } 
    $location.path("/"); 
}; 


}]); 

定向TemplateURL(新增销售页) - 所以,当我点击保存或取消,无论它重定向我回到主网页

<div class="form-group"> 
    <button ng-click="save()" class="btn btn-primary">Save</button> 
    <button ng-click="cancel()" class="btn btn-primary">Cancel</button> 
</div> 

新增销售控制器

app.controller('addController', ['$scope', '$location', '$routeParams', 'salesService', 
           function($scope, $location, $routeParams, salesService){ 
$scope.save = function() 
{ 
    salesService.addSales({id: $scope.Item.id, item: $scope.Item.item, name: $scope.Item.name, date: $scope.Item.date, price: $scope.Item.price}); 
    $location.path('/'); 
}; 

$scope.cancel = function() 
{ 

    alert("deleted item asdasd"); 
    $scope.$apply(function() { 
     $location.path('/'); 
    }); 
}; 
}]); 

回答