我有一个单页面应用程序,但在我的UI中加载内容时遇到问题
所以我的index.html就是这样的
html lang="en" ng-app="App" ng-controller="IndexController">
<head>
<!-- CORE CSS-->
<link href="css/materialize.min.css" type="text/css" rel="stylesheet" media="screen,projection">
<link href="css/style.min.css" type="text/css" rel="stylesheet" media="screen,projection">
<link href="css/custom/custom.min.css" type="text/css" rel="stylesheet" media="screen,projection">
<script type="text/javascript" src="js/plugins/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="libs/angular/angular.min.js"></script>
<script type="text/javascript" src="libs/angular-route/angular-route.min.js"></script>
<script type="text/javascript" src="libs/angular-utils-pagination/dirPagination.js"></script>
<script type="text/javascript" src="js/materialize-plugins/date_picker/picker.js"></script>
<script type="text/javascript" src="js/materialize-plugins/date_picker/picker.date.js"></script>
<script type="text/javascript" src="js/ngStorage.min.js"></script>
<script type="text/javascript" src="js/plugins/select2.js"></script>
<script type="text/javascript" src="js/controller/IndexController.js"></script>
<script type="text/javascript" src="js/appRoutes.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body class="cyan">
*some navbar codes here*
<section id="content">
<div ng-view>
</div>
</section>
</body>
*some scripts here*
</html>
然后我有我的其他页面
<section id="content" ng-controller="DashboardController">
*some codes here*
<select required id="names" ng-model="selectedName" ng-class="{invalid : validation.names}" ng-options="x for x in names"></select>
<div class="row">
<div ng-repeat="x in names">
{{x}}
</div>
</div>
<div class="row">
<div class="input-field col s4"></div>
<div class="input-field col s4">
<a class="btn waves-effect waves-light white blue-text" ng-click="cancelRequest()">Cancel</a>
<a class="btn waves-effect waves-light blue" ng-click="transaction()">Save</a>
</div>
<div class="input-field col s4"></div>
</div>
</section>
问题是我无法使用选择,收音机,复选框等。
在我的仪表板控制器中,我有一个名为$scope.names
的列表,其中数据为$scope.names = ["Emil", "Tobias", "Linus"];
,并在我的init函数中声明
使用ng-repeat显示但不在ng-options
中显示有人可以告诉我出了什么问题吗?我已经绞尽脑汁好几个小时了:(
我也有
$(document).ready(function () {
$('select').material_select();
});
如果我对<option></option>
进行了硬编码,除非我提出
<script type="text/javascript" src="js/materialize.min.js"></script>
<script type="text/javascript" src="js/plugins/angular-materialize.js"></script>
<script type="text/javascript" src="js/plugins.min.js"></script>
编辑:
.controller('DashboardController', function ($http,$scope,$sessionStorage,StartingService,LogService,SweetAlert) {
(function init() {
$http.defaults.headers.common['Authorization'] = $sessionStorage.authenticate;
$scope.isLogin = $sessionStorage.showLogin;
$sessionStorage.currentBusiness;
$(document).ready(function () {
$('select').material_select();
$('.tooltipped').tooltip({delay: 50});
});
答案 0 :(得分:0)
所以我认为你应该像这样使用$ onInit():
controller: function() {
this.$onInit = function() {
$('select').material_select();
};
},
或者在$ timeout上选择初始化:
$timeout(() => $('select').material_select());
你不需要包装代码来运作
.controller('DashboardController', function ($http,$scope,$sessionStorage,StartingService,LogService,SweetAlert, $timeout) {
$http.defaults.headers.common['Authorization'] = $sessionStorage.authenticate;
$scope.isLogin = $sessionStorage.showLogin;
$sessionStorage.currentBusiness;
$timeout(function () {
$('select').material_select();
$('.tooltipped').tooltip({delay: 50});
});