【发布时间】:2016-12-21 09:59:34
【问题描述】:
在我的 (monaca /onsen UI angularjs) 应用程序中,我想在项目启动时加载我的项目
<script>
ons.bootstrap()
.controller('AppController', function() {
this.pushes = 0;
this.pops = 0;
this.details = 0;
this.showDetails = function(){
if (this.details == 1)
this.details = 0;
else
this.details = 1;
}
this.getProjects = function(){
console.log('getData');
$http.get("http://localhost:3000/api/getAllProject")
.then(function(response) {
this.projects = response.data;
console.log('Projects: '+this.projects)
});
}
});
</script>
这是html页面
<body ng-controller="AppController as app">
<ons-sliding-menu
menu-page="menu.html" main-page="home.html" side="left"
var="menu" type="reveal" max-slide-distance="260px" swipable="true">
</ons-sliding-menu>
<ons-template id="home.html">
<ons-navigator var="myNav">
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="menu.toggle()">
<ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">Projects</div>
<div class="right">
<ons-toolbar-button>
<ons-icon icon="refresh" size="30px" fixed-width="true"></ons-icon>
</ons-toolbar-button>
</div>
</ons-toolbar>
<ons-list>
<ons-list-item ng-click="app.showDetails()" ng-repeat="item in app.projects">
{{item.projectcode}}
</ons-list-item>
<div ng-show="app.details==1">
<p ng-click="myNav.pushPage('level1.html')"> Levels </p>
</div>
</ons-list>
</ons-page>
</ons-navigator>
</ons-template>
如您所见,我需要在应用程序启动时从 AppController 调用函数 getProjects(),以便我可以从数据库中获取项目以显示它
【问题讨论】: