我仅具有AngularJS的基本知识。我创建了一个带有多个html页面的AngularJS应用程序。这是我的主要观点html.Im很抱歉,我的问题是如此之久。但这是更好的方式来问我的问题。如何使用角度正确地路由多个html页面
Main.cshtml
<html ng-app="myapp">
<head>
<meta name="viewport" content="width=device-width" />
<title>Main</title>
<!-- Main CDN Links-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/bootstrap/3.3.1/css/bootstrap-theme.css">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<!-- end-->
<link href="~/Content/Css/sidebar.css" rel="stylesheet" />
<style>
* {
border-radius: 0 !important;
}
</style>
</head>
<body>
<div class="nav-side-menu">
//some code
</div>
<div class="nav-top-menu nav-top">
//some code
</div>
<div class="contents" id="subContents" ui-view>
//route my sub views to here
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script src="//angular-ui.github.io/ui-router/release/angular-ui-router.js"></script>
<script src="~/Scripts/smart-table.debug.js"></script>
<script src="~/Scripts/MainView.js"></script>
</body>
</html>
MainView.js
var myapp = angular.module('myapp', ["ui.router"]);
myapp.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/route1")
$stateProvider
.state('sideMenuCustomerDivition', {
templateUrl: "Main/Customer"
})
.state('sideMenuDashboardDivition', {
templateUrl: "Main/Staff"
})
})
我有我的路线另一个HTML视图到main.cshtml.This是,鉴于HTML
Customer.cshtml
个<html>
<body ng-app="customerTableApp">
<div ng-controller="safeCtrl">
<button type="button" ng-click="addRandomItem(row)" class="btn btn-sm btn-success">
<i class="glyphicon glyphicon-plus">
</i> Add random item
</button>
<table st-table="displayedCollection" st-safe-src="rowCollection" class="table table-striped">
<thead>
<tr>
<th st-sort="firstName">first name</th>
<th st-sort="lastName">last name</th>
<th st-sort="birthDate">birth date</th>
<th st-sort="balance">balance</th>
</tr>
<tr>
<th colspan="5"><input st-search="" class="form-control" placeholder="global search ..." type="text" /></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in displayedCollection">
<td>{{row.firstName}}</td>
<td>{{row.lastName}}</td>
<td>{{row.birthDate}}</td>
<td>{{row.balance}}</td>
<td>
<button type="button" ng-click="removeItem(row)" class="btn btn-sm btn-danger">
<i class="glyphicon glyphicon-remove-circle">
</i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
<script src="~/Scripts/CustomerView.js"></script>
</body>
</html>
CustomerView.js
var app = angular.module('customerTableApp', ['smart-table'])
app.controller('safeCtrl', ['$scope', function ($scope) {
var firstnames = ['Laurent', 'Blandine', 'Olivier', 'Max'];
var lastnames = ['Renard', 'Faivre', 'Frere', 'Eponge'];
var dates = ['1987-05-21', '1987-04-25', '1955-08-27', '1966-06-06'];
var id = 1;
function generateRandomItem(id) {
var firstname = firstnames[Math.floor(Math.random() * 3)];
var lastname = lastnames[Math.floor(Math.random() * 3)];
var birthdate = dates[Math.floor(Math.random() * 3)];
var balance = Math.floor(Math.random() * 2000);
return {
id: id,
firstName: firstname,
lastName: lastname,
birthDate: new Date(birthdate),
balance: balance
}
}
$scope.rowCollection = [];
for (id; id < 5; id++) {
$scope.rowCollection.push(generateRandomItem(id));
}
$scope.displayedCollection = [].concat($scope.rowCollection);
$scope.addRandomItem = function addRandomItem() {
$scope.rowCollection.push(generateRandomItem(id));
id++;
};
$scope.removeItem = function removeItem(row) {
var index = $scope.rowCollection.indexOf(row);
if (index !== -1) {
$scope.rowCollection.splice(index, 1);
}
}
}]);
我知道问题出在NG-应用程序连到另一个NG-app.Anyone可以给我来查看已经排到了this.Template更好的解决方案。我的问题是我无法将值分配到第二个视图。客户视图显示在侧面主视图中。但分配的值不显示。浏览器显示该类型的错误。
Error: [ng:areq] http://errors.angularjs.org/1.3.9/ng/areq?p0=safeCtrl&p1=not%20aNaNunction%2C%20got%20undefined at Error (native) at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:6:416 at Qb (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:19:417) at sb (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:20:1) at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:76:95 at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:57:257 at s (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:7:408) at v (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:57:124) at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:52:9) at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js:51:118
如果Customer.cshtml应该是一个视图,它不应该是一个完整的HTML文档。剥离顶级html和body标签,所以顶级标签是div。 – 2015-01-21 04:17:55