Angularjs 无法将自定义指令用于模态
我是新手。我已经创建了一个自定义指令(templateUrl:modal directive.html),其中包含引导模式。当我在索引页面中使用该指令时,模态不会弹出。然而,当我只运行modal-directive.html时,模态就会弹出 我做错了什么Angularjs 无法将自定义指令用于模态,angularjs,Angularjs,我是新手。我已经创建了一个自定义指令(templateUrl:modal directive.html),其中包含引导模式。当我在索引页面中使用该指令时,模态不会弹出。然而,当我只运行modal-directive.html时,模态就会弹出 我做错了什么 angular.module('mainApp', []) .directive('modal-directive', function () { return { templateUrl: "modal-d
angular.module('mainApp', [])
.directive('modal-directive', function () {
return {
templateUrl: "modal-directive.html",
restrict: 'EA'
}
})
Index.html
<html ng-app="mainApp">
<head>
<title></title>
<meta charset="utf-8" />
<script src="script/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
Hello from Index
<div>
<modal-directive></modal-directive>
</div>
</body>
</html>
你好,来自索引
modal-directive.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<script src="script/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<p>Hello from modal directive</p>
<form>
<button type="button" style="position:page" class="btn btn-primary" data-toggle="modal" data-target="#employeeSearchModal">
View Employee
</button>
</form>
<div id="employeeSearchModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"><b>Search Employee</b></h4>
</div>
<div class="modal-body">
<form class="form-inline">
<div class="form-group">
<input type="text" id="searchEmp" ng-model="searchEmpno" placeholder="Enter Employee id" class="form-control" />
<button data-dismiss="modal" class="btn btn-primary" data-toggle="modal" data-target="#employeeDetailsModal" ng-click="doSearch()">Search</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
你好,来自模态指令
查看员工
&时代;
搜索员工
搜寻
首先:从modal-directive.html中删除
,
标记,直接放置内容,因为index.html已经加载了脚本和样式!我已经试过了,但是运气不好。。甚至在index.html中也没有弹出消息“p>Hello from modal directive”