我是棱角分明的新人。我想知道如何在ng-view中为html加载javascript。
我看过像添加jquery这样的答案。你能帮我解决一下究竟要添加的内容和文件。
我的文件在下面给出
<!Doctype HTML>
<html ng-app="adminHomeApp" style="height: 100%;">
<head>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="js/admin/adminHomeApp.js"></script>
</head>
<body style="height:100%">
<table width="100%" border="1" height="80%">
<tr height="10%">
<td width="100%" colspan="2" align="center" valign="middle"><h1>Admin Home</h1></td>
</tr>
<tr height="90%" valign="top">
<td width="10%" ng-include="'/views/admin/index.html'"></td>
<td width="90%" valign="middle" align="center">
<table width="100%" height="100%">
<tr width="100%" height="100%">
<td align="center" valign="middle"><div ng-view /></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
&#13;
//Define an angular module for our app
var adminHomeApp = angular.module('adminHomeApp', ['ngRoute']);
adminHomeApp.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/addCategory', {
templateUrl : '/views/admin/addCategory.html',
});
} ]);
&#13;
<script src="bower_components/jqlite/jquery.js"></script>
<script src="/js/admin/category/categoryApp.js"></script>
<table border="1" ng-controller="CategoryController">
<tr>
<td>Category Name</td>
<td><input type="text" name="category.name" /></td>
</tr>
<tr>
<td>Parent</td>
<td>
<select ng-model="category" ng-options="category.name for category in categories"></select>
</td>
</tr>
<tr>
<td colspan="2"><button type="button">Add</button></td>
</tr>
</table>
&#13;
adminHomeApp.controller('CategoryController', [ '$scope', function($scope) {
$scope.categories = [
{name:'--Select One--'},
{name:'cat1'},
{name:'cat2'}
];
$scope.category = $scope.categories[0];
}]);
&#13;
答案 0 :(得分:0)
我认为你已经以正确的方式完成了,但你的部分内容是'/views/admin/addCategory.html'
所以你需要从那里指出js文件
试
<script src="../bower_components/jqlite/jquery.js"></script>
<script src="../js/admin/category/categoryApp.js"></script>