2015-09-20 60 views
0

这里是app.js添加新的价值模型没有显示

angular.module('mobApp', ['ionic', 'mobApp.controllers', 'mobApp.services', 'ngCordova']) 

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 

    }); 
}) 

.config(function($stateProvider, $urlRouterProvider) { 
    $stateProvider 

    .state('listitems', { 
     url: '/listitems', 
     templateUrl: 'templates/listitems.html' 
    }) 

    .state('publishmsg/form/new-message', { 
     url: '/publishmsg/form/new-message', 
     templateUrl: 'templates/publish-msg/publishmsg-form.html', 
     controller: 'publishMessageFormController' 
    }) 

    .state('publishmsg/form/add-tags', { 
     url: '/publishmsg/form/add-tags', 
     templateUrl: 'templates/publish-msg/publishmsg-form-tags.html', 
     controller: 'publishMessageFormController' 
    })  

    .state('publishmsg/form/add-location', { 
     url: '/publishmsg/form/add-location', 
     templateUrl: 'templates/publish-msg/publishmsg-form-location.html', 
     controller: 'publishMessageFormController' 
    }); 

    $urlRouterProvider.otherwise('/listitems'); 
}); 

这里是publishMessageFormController

angular.module("mobApp.controllers",['ionic','ngTagsInput','google.places']) 
.controller("publishMessageFormController",function($scope, $http, $location, $ionicLoading, $cordovaToast, $compile, deviceStatus, $cordovaImagePicker, $ionicHistory){ 

$scope.finalPubFormModal = {}; 

$scope.geoSelectionDone = function() 
{ 

     $scope.finalPubFormModal.location = "fObj"; 
     console.log("Log1"+JSON.stringify($scope.finalPubFormModal));  
} 

$scope.submitNewPublishMessage = function() 
{ 
    console.log("Log2"+JSON.stringify($scope.finalPubFormModal)); 
} 

这里是publishmsg-form-location.html

<ion-view view-title="Search Location"> 
    <ion-nav-buttons side="right"> 
    <button class="button button-icon icon ion-android-done" ng-disabled="npubmUsrLocForm.form.$invalid" ng-click="geoSelectionDone()"></button> 
    </ion-nav-buttons> 
    <ion-content> 
    <form name="npubmUsrLocForm.form" class="css-form" novalidate> 
     <div class="list"> 
      <label class="item item-input"> 
       <input placeholder="Type location name" type="text" ng-model="userCustmLocModel.location" ng-minlength="3" required/> 
      </label> 
     </div> 
    </form> 
    </ion-content> 
</ion-view> 

这里是publishmsg-form.html

<ion-view view-title="Publish message"> 
    <ion-nav-buttons side="right">  
    <button class="button button-icon icon ion-android-done" ng-disabled="npubmForm.msgForm.$invalid" ng-click="submitNewPublishMessage()"></button> 
    </ion-nav-buttons> 

的问题是内部控制log1打印新location值,但log2

回答

0

我认为,原因是每个页面有控制器的一个单独的实例。您可以尝试通过服务共享数据。像

angular.module('mobApp.services').service('finalPub', function() { 
    this.finalPubFormModal = {};  
    this.geoSelectionDone = function(value) 
    { 
     this.finalPubFormModal.location = value; 
    } 
}); 

的东西,那么你包括你的控制器,服务

.controller("publishMessageFormController",function($scope, $http, $location, $ionicLoading, $cordovaToast, $compile, deviceStatus, $cordovaImagePicker, $ionicHistory,finalPub){ ... 

然后用役中的控制器

$scope.geoSelectionDone = function() 
{ 
     finalPub.geoSelectionDone("fObj"); 
} 
+0

但在app.js你可以看到所有页面我是指的同一个控制器 – manish

+0

这是事实,但据我记得,控制器的新实例将每一条路线的创造 - 给你的OOP并行,认为它是这样的:你定义的类酒馆lishMessageFormController,然后创建var controller1 = new publishMessageFormController(),var controller2 = new publishMessageFormController() - 如果你在controller1中设置了一些东西,controller2中什么都不会改变。 –