角路由,当前路线按钮/从缺省路由

角路由,当前路线按钮/从缺省路由

问题描述:

引导保持它短后反应迟钝的功能,它的一个单页应用程序,以便的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('/'); 
    }); 
}; 
}]); 
+0

检查错误控制台。如果没有错误,发布一个plunkr来重现问题。不,你为什么不只是使用''为你的链接? –

+0

plunker使得它最糟糕的,因为一切犯规秀(?),不知道这是在我结束一个错误(https://plnkr.co/edit/AToS79LLSVfo5li65awo?p=preview),检查三次。如果我使用则不需要路由。 –

+0

一旦你删除所有无用的jQuery和引导JS,一旦你把正确的位置为angular.js,一旦你删除使用一个未定义的dateTimeController的部分,一旦你删除无用$范围。$适用()从取消( )函数,一切工作正常:https://plnkr.co/edit/Lthey4J7n0DXUVWaeAkE?p=preview。与href的链接指向映射到路由的URL。当点击一个带有href指向URL的链接时,角度将该位置设置为该URL,路由器检测到位置更改,然后导航到映射到此URL的路由。 –

尝试在$locationProviderhtml5mode属性设置为true