【发布时间】:2013-08-10 06:06:15
【问题描述】:
我有一个带有“刷新”链接的 AngularJS 测试页面,该链接调用一个函数,作为回报,该函数会更新模型“customer.name”
但是,“刷新”点击仍然没有改变视图中的 {{customer.name}},我不明白为什么。
这是我的申请内容。
index.html
<!doctype html>
<head>
<title>Test</title>
</head>
<body ng-app="roaMobileNgApp">
<script src="scripts/angular.js"></script>
<script src="scripts/angular-ui.js"></script>
<link rel="stylesheet" href="scripts/angular-ui.css">
<div class="container" ng-view=""></div>
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
</body>
</html>
app.js
'use strict';
angular.module('roaMobileNgApp', ['ui'])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
});
main.js
'use strict';
angular.module('roaMobileNgApp')
.controller('MainCtrl', function ($scope) {
$scope.customer = {name: '',
id: 0};
$scope.getDetails = function() {
$scope.customer.name = 'Test';
};
});
main.html
<a href="#" ng-click="getDetails()">Refresh</a>
<p><input type="text" ng-model="customer.name"> {{ customer.name }} </p>
</div>
【问题讨论】:
-
使用按钮,您正在刷新页面。要么将您的 href 更改为 void javascript 对象。