角度选项卡在通过路由调用的模板中不起作用
Angular tab is not working in template calling through routes
我正在尝试在模板中运行该选项卡,该选项卡包含在使用路由的ng-view
中。不幸的是,当我单击模板时,它不起作用。请帮助我解决问题。这是代码:
索引.html
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8" />
<title>AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28//angular-route.min.js"></script></head>
<script src="app.js"></script>
</head>
<body ng-controller="application">
<header><a href="#/template1">Template 1</a><br /><a href="#/template2">Template 2</a></header>
<div ng-view="templateUrl"></div>
</body>
</html>
模板1.html
I am template 1
模板2.html
<div role="presentation" class="text-center" ng-repeat="listitem in patient_tab">
<a href="javascript:void(0)" ng-click="tabClick(clickTab)">
<i class="{{ listitem.patientTab_icon }}" aria-hidden="true"></i> <br />
{{ listitem.patientTab_name }}
</a>
</div>
<ng-include src="patient_template"></ng-include>
I am template 2
模板1.html
I am ptemplate 1
模板2.html
<h2>Patient template 2</h2>
应用.js
var medicalapp = angular.module('app', ['ngRoute']);
medicalapp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/template1', {
templateUrl: 'template1.html',
controller: 'template_controller1'
}).
when('/template2', {
templateUrl: 'template2.html',
controller: 'template_controller2'
}).
otherwise({
redirectTo: '/template1'
});
}]);
medicalapp.controller('application', function($scope){
});
medicalapp.controller('template_controller2', function($scope){
$scope.patient_tab= [
{
patientTab_name: 'ptemplate1',
url: 'patient_template1.html',
patientTab_icon: 'fa fa-area-chart'
},
{
patientTab_name: 'ptemplate2',
url: 'patient_template1.html',
patientTab_icon: 'fa fa-file-text'
},
];
$scope.patient_template = 'patient_template1.html';
$scope.tabClick= function(tab){
$scope.patient_template = tab.url;
}
});
谢谢伙计们..寻求帮助。答案是:-
模板2.html
<div role="presentation" class="text-center" ng-repeat="listitem in patient_tab">
<a href="javascript:void(0)" ng-click="tabClick(listitem)">
<i class="{{ listitem.patientTab_icon }}" aria-hidden="true"></i> <br />
{{ listitem.patientTab_name }}
</a>
</div>
应用.js
var medicalapp = angular.module('app', ['ngRoute']);
medicalapp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/template1', {
templateUrl: 'template1.html',
controller: 'template_controller1'
}).
when('/template2', {
templateUrl: 'template2.html',
controller: 'template_controller2'
}).
otherwise({
redirectTo: '/template1'
});
}]);
medicalapp.controller('application', function($scope){
});
medicalapp.controller('template_controller2', function($scope){
$scope.patient_tab= [
{
patientTab_name: 'ptemplate1',
url: 'patient_template1.html',
patientTab_icon: 'fa fa-area-chart'
},
{
patientTab_name: 'ptemplate2',
url: 'patient_template1.html',
patientTab_icon: 'fa fa-file-text'
},
];
$scope.patient_template = 'patient_template1.html';
$scope.tabClick= function(listitem ){
$scope.patient_template = listitem.url;
}
});
名称或字符串ng-click="tabClick(listitem)">
即列表项应相同
$scope.tabClick= function(listitem ){
$scope.patient_template = listitem.url;
}
相关文章:
- javascript函数调用不起作用
- Ajax调用不起作用
- 函数调用不起作用
- IE9+IE10 AJAX调用不起作用
- 科尔多瓦脸书登录FB.api调用不起作用
- 为什么这个javascript函数调用不起作用
- Ajax和jQuery对$Ajax url的调用不起作用
- firefox扩展对$.ajax的调用不起作用
- jQuery函数调用不起作用
- AJAX调用不起作用,因为它继续转到链接
- 表单提交前的Ajax调用不起作用
- 通过引用进行的Javascript调用不起作用
- 使用 ajax 的 API 调用不起作用
- Ajax 调用不起作用此代码中的问题
- JQuery .ajax() 函数调用不起作用,但成功方法运行
- JavaScript中的递归调用不起作用
- JQuery REST 调用不起作用
- 完整日历 GetEvents() 方法调用不起作用
- 从提交输入对函数的单击调用不起作用
- 下拉元素选择和 JS 调用不起作用