【发布时间】:2015-08-26 23:09:28
【问题描述】:
我正在尝试使用 ng-view 构建单页应用程序,但此时我遇到了关于 ng-model 的问题。我已经按照本教程here 进行了操作,除了 ng-model 之外,一切都运行良好。 我添加了一个带有 ng-model 的单个输入文本的表单和一个在我的控制器中调用函数的按钮。提交按钮后,我会加载一个视图,在其中尝试获取我的 ng-model 但没有成功...
见下面我的代码:
home.html
<div>
<h2>Home Page</h2>
<form>
<input type="text" ng-model="actia.name" placeholder="Saisir un mot"><br>
<button ng-click="toSend()">OK</button>
</form>
</div>
app.js
var MyApp = angular.module('MyApp', ['ngRoute']);
MyApp.config(function($routeProvider, $locationProvider){
$routeProvider
.when('/',{
templateUrl : 'pages/home.html',
controller : 'MainController'
}).when('/contact',{
templateUrl : 'pages/contact.html',
controller : 'MainController'
});
// $locationProvider.html5Mode(true);
});
MyApp.controller('MainController', function($scope, $location){
$scope.message = "Message du main Control";
$scope.actia = {
name : '',
lastname : 'goerge'
};
$scope.toSend = function(){
var donnees = $scope.actia;
// $location.url('/contact');
console.log(donnees);
};
});
contact.home
<div>
<h2>Contact Page</h2>
<p>Value is : {{actia.name}} {{actia.lastname}}</p>
</div>
显示{{actia.lastname}},但不显示{{actia.name}}
你有什么建议来解决这个问题吗?
提前致谢
【问题讨论】:
标签: angularjs angular-ngmodel ng-view