Angularjs 更改模型的值不会产生任何效果

Angularjs 更改模型的值不会产生任何效果,angularjs,angularjs-scope,Angularjs,Angularjs Scope,这里是app.js的 angular.module('mobApp', ['ionic', 'mobApp.controllers', 'mobApp.services', 'ngCordova']) .run(function($ionicPlatform) { $ionicPlatform.ready(function() { }); }) .config(function($stateProvider, $urlRouterProvider) { $stateProvid

这里是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.testModel = "Hello";

$scope.gotoAddTag = function()
  {
    $scope.testModel = "Hi";
    $location.path('publishmsg/form/add-tags');
  }
下面是publishmsg表单标签.html:

<ion-view view-title="Add Tags">
  <ion-nav-buttons side="right">
    <a class="button button-icon icon ion-android-done" href="#" ng-click="tagSelectionDone()"></a>
  </ion-nav-buttons>
  <ion-content class="padding"> 
            <input type="text" ng-model="testModel" />     
  </ion-content>
</ion-view>


问题在
gotoAddTag()
内部,即使将
testModel
分配给
Hi
后,文本字段的值仍然是
Hello
这看起来像是范围层次结构的误解。您应该将模型包装在父对象中,以确保更改了正确的键。例如:

$scope.model = {
    testModel: 'Hello'
};
然后

$scope.model.testModel = 'Hi';
基本上,读写的$scope在两种上下文中都是不同的。你可以在这里读更多


不要将值直接绑定到范围。