右对齐,我想要部分视图取决于哪个选项卡被点击.在线找到一些示例代码让我开始,但是无法通过执行示例代码找出选项卡
的index.html
<!doctype html> <html ng-app="mainApp"> <head> </head> <body> <div ng-view> </div> <script src="scripts/lib/angular.min.js"></script> <script src="scripts/lib/angular-route.min.js"></script> <script src="scripts/lib/bootstrap.min.js"></script> <script src="app.js"></script> </body> </html>
app.js:
var mainApp = angular.module('mainApp',['ngRoute']); mainApp.config(function($routeProvider){ $routeProvider.when('/',{ controller: 'SearchController',templateUrl: 'search.html' }) })
Search.html
<div ng-controller="SearchController"> </div>
SearchController:
样品取自实例
angular.module('mainApp').controller('SearchController',function ($scope,$window) { $scope.tabs = [ { title:'Dynamic Title 1',content:'Dynamic content 1' },{ title:'Dynamic Title 2',content:'Dynamic content 2',disabled: true } ]; $scope.alertMe = function() { setTimeout(function() { $window.alert('You\'ve selected the alert tab!'); }); }; });
错误:
[ng:areq] http://errors.angularjs.org/1.4.4/ng/areq?p0=search%2FSearchController.js&p1=not%20aNaNunction%2C%20got%20undefined
看起来它在一起找不到SearchController.您的SearchController是否在自己的文件中?如果是这样,请务必将其加载到您的index.html!
原文链接:https://www.f2er.com/angularjs/140707.html所以,
<script src="scripts/lib/angular.min.js"></script> <script src="scripts/lib/angular-route.min.js"></script> <script src="scripts/lib/bootstrap.min.js"></script> <script src="app.js"></script> <script src="path/to/controller/SearchController.js"></script>
编辑:
啊,我看到这个问题.您尚未在您的app.js中定义“SearchController”.
去做这个 –
在SearchController.js中,将angular.module(‘mainApp’)更改为angular.module(‘SearchController’)了解您正在创建一个尚未与“mainApp”模块分开的角度模块.
然后,在你的app.js中,var mainApp = angular.module(‘mainApp’,[‘ngRoute’,’SearchController’]);这将适当地将您的控制器注入到您的应用程序中,并且可以由您的路由器正确使用.