【发布时间】:2017-09-27 10:08:13
【问题描述】:
我正在使用 angularjs。我有一个header.html,我已经使用 ng-include 将该 html 页面合并到另一个 html 中。
另外,我在header.html 中有一个下拉列表,我希望显示所选值(来自下拉列表)列表。我该怎么做?
header.html
<html ng-app="app" >
<head>
<script src="assets/js/jquery-2.1.4.min.js"></script>
<script src="controller/headerctrl.js"></script>
</head>
<body ng-controller="headerctrl">
<select id="valueid" class="form-control" required typeof="text" ng-model="valuselect" form="Floorform" >
<option value="">Select</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div>
</body>
</html>
内容.html
<html ng-app="app" >
<head>
<script src="assets/js/jquery-2.1.4.min.js"></script>
<script src="controller/Contentctrl.js"></script>
</head>
<body >
<div id="header" ng-controller="headerctrl" ng-include="'header.html'">
</div>
<div id="sidebar" class="sidebar responsive ace-save-state" ng-controller="Contentctrl" >
//hi this content page here i get header dropdown selected value
</div>
</body>
</html>
标头控制器
var app = angular.module("app", []);
app.controller('headerctrl', ['$scope', '$http', '$window',
function ($scope, $http, $window, ) {
}]);
内容控制器
var app = angular.module("app", []);
app.controller('contentctrl', ['$scope', '$http', '$window',
function ($scope, $http, $window, ) {
}]);
【问题讨论】:
-
为什么在 header 中使用 ng-app
-
我的模块名称
-
我会尝试创建 plnkr 。你应该阅读github.com/johnpapa/angular-styleguide/tree/master/a1。这是非常好的角度指南
-
@ThanhTùng 在
html元素中使用ng-app很好 -
请检查我会更新代码@ThanhTùng @k Scaandrett
标签: angularjs drop-down-menu controller mean-stack