这是我的HTML代码
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<!-- load angular via CDN -->
<script src="//code.angularjs.org/1.4.0-rc.2/angular.min.js"></script>
<script src="//code.angularjs.org/1.4.0-rc.2/angular-route.min.js ">
</script>
<script src="v2-app.js"></script>
<script src="components/where-to-buy/whereToBuyController.js"></script>
<script src="components/sku-listing/deviceController.js"></script>
<script src="directives.js"></script>
<nav class="tab-nav">
<div class="tab-nav-inner">
<div class="container-fluid" ng-controller="mainController">
<div class="row">
<ul class="nav nav-pills nav-justified th-menu">
<li role="presentation" ng-class="{active:isActive('/about')}" ><a href="#/about" ng-click="scrollToSection('content-section')">Erafone offer details</a></li>
<li role="presentation" ng-class="{active:isActive('/form')}"><a href="#/form" ng-click="scrollToSection('content-section')">Form</a></li>
</ul>
</div>
</div>
</div>
</nav>
<!-- Tab panes -->
<div class="container-fluid">
<ng-view>
</ng-view>
我想使用angular js在点击表单上加载html视图文件。 这是我的js代码
var dgApp = angular.module('dgApp', ['ngRoute']);
// ROUTE
dgApp.config(function($routeProvider){
$routeProvider
.when('/about',{
templateUrl: 'components/additional-info/v2-
additionalInfoView.html',
controller : 'mainController'
})
.when('/form',{
templateUrl: 'components/form/v2-formView.html',
controller : 'mainController'
})
.otherwise({ redirectTo: '/about' })
});
dgApp.controller('mainController', ['$scope' , '$location', '$http',
'$filter', function ($scope, $location, $http, $filter) {
$scope.scrollToSection = function(sectionID){
$('html, body').animate({
scrollTop: $("#"+sectionID).offset().top - 63
}, 800);
}
}]);
控制台中有错误
ReferenceError:未定义angular v2-app.js:2:4
TypeError:dgApp是undefined directives.js:1:0
TypeError:$不是函数index.html:143:5
所以我想在ng-view中的同一页面上点击表单链接加载html视图文件。我在上面的代码中犯了什么错误?如果有人有任何想法,请指导我。
答案 0 :(得分:1)
您的错误堆栈跟踪清楚地表明您错过了添加angular.js
&amp; jquery.js
,尝试添加可以解决问题的问题
序列将是
修改强>
要在点击时加载您的观看次数,您需要从.otherwise({ redirectTo: '/about' })
查看更新的plunkr
$routeProvider