diff --git a/Gruntfile.js b/Gruntfile.js index 7a4371e5cd..80713331ea 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -33,6 +33,7 @@ module.exports = function(grunt) { distAngular: { src: [ 'js/ext/angular/src/ionicAngular.js', + 'js/ext/angular/src/service/**/*.js', 'js/ext/angular/src/directive/**/*.js' ], dest: 'dist/<%= pkg.name %>-angular.js' diff --git a/dist/ionic-angular.js b/dist/ionic-angular.js index d2f4aef35e..78dffafffd 100644 --- a/dist/ionic-angular.js +++ b/dist/ionic-angular.js @@ -1,5 +1,21 @@ angular.module('ionic.ui', ['ionic.ui.content', 'ionic.ui.tabs', 'ionic.ui.nav', 'ionic.ui.sideMenu']); ; +angular.module('ionic.service', []) + +.factory('TemplateLoader', ['$q', '$http', '$templateCache', function($q, $http, $templateCache) { + return { + load: function(url) { + var deferred = $q.defer(); + + $http.get(url, { cache: $templateCache }).success(function(html) { + deferred.resolve(html && html.trim()); + }); + + return deferred.promise; + } + } +}]); +; angular.module('ionic.ui.content', {}) // The content directive is a core scrollable content area @@ -24,13 +40,26 @@ angular.module('ionic.ui.content', {}) } }) ; -angular.module('ionic.ui.nav', []) +angular.module('ionic.ui.nav', ['ionic.service']) -.controller('NavCtrl', function($scope, $element, $compile) { +.controller('NavCtrl', ['$scope', '$element', '$compile', 'TemplateLoader', function($scope, $element, $compile, TemplateLoader) { var _this = this; angular.extend(this, ionic.controllers.NavController.prototype); + this.pushFromTemplate = function(tmpl) { + data = TemplateLoader.load(tmpl).then(function(data) { + console.log('Nav loaded template', data); + + var childScope = $scope.$new(); + childScope.isVisible = true; + + $compile(data)(childScope, function(cloned, scope) { + $element.append(cloned); + }); + }); + } + ionic.controllers.NavController.call(this, { content: { }, @@ -38,34 +67,28 @@ angular.module('ionic.ui.nav', []) shouldGoBack: function() { }, setTitle: function(title) { - $scope.title = title; + $scope.navController.title = title; }, showBackButton: function(show) { }, } }); - $scope.controllers = this.controllers; - - $scope.getTopController = function() { - return $scope.controllers[$scope.controllers.length-1]; - } - - $scope.pushController = function(controller) { - _this.push(controller); - } + $scope.pushController = function(scope) { + _this.push(scope); + }; $scope.navController = this; -}) +}]) -.directive('navController', function() { +.directive('navCtrl', function() { return { restrict: 'E', replace: true, transclude: true, controller: 'NavCtrl', //templateUrl: 'ext/angular/tmpl/ionicTabBar.tmpl.html', - template: '