我試圖填充一個ion-content
容器。我想HTML加載到$scope
取決於哪個選項卡用戶點擊:
<ion-tabs tabs-type="tabs-icon-only">
<ion-tab ...>
<ion-tab title="Create" icon-on="ion-android-create">
<ion-content padding="true" class="has-header">
{{getCreate}}
</ion-content>
</ion-tab>
<ion-tab ...>
</ion-tabs>
這是此視圖中的控制器:
(function() {
'use strict';
angular.module('ionicApp')
.controller('HomePageController', ['$scope', '$state', '$templateCache', HomePageController]);
function HomePageController($scope, $state, $templateCache) {
$scope.getCreate = function() {
// at the moment create.html is just simple static html.
return $templateCache.get('app/views/home/ads/create.html');
//return $templateCache.get('main.create'); // this also doesn't work
};
}
})
();
的兩個相關的狀態被定義爲:
.state('main.home', {
url: '/home',
views: {
'main': {
templateUrl: 'app/views/home/home.html',
controller: 'HomePageController'
}
}
})
.state('main.create', {
url: '/create',
views: {
'main': {
templateUrl: 'app/views/home/ads/create.html',
controller: 'CreateAdController'
}
}
})
我對此有錯嗎?在我的HomePageController
中,我需要做什麼才能將create.html
加載到$scope.getCreate
?
這是* *幾乎完美,除了線' '創造':{'。當我指定視圖名稱創建時,它不起作用,但是當我使用'main'時,它確實如此。任何想法爲什麼? – DaveDev
嗯,不確定。我比'Ionic版本更熟悉'angular-ui-router'。很高興幫助:) –