我在http://jsfiddle.net/gsche/1/上写了一些简化的代码
单击"刷新"链接时,"customer.name"模型不会更新视图.
我在本地计算机上编写了代码,并在Chrome中使用Batarang进行了调试.
控制台不显示任何错误.Batarang中的Model页面显示右侧更改的客户名称,与旧范围ID相关联,但$ scopes的ID也会更改.
谁能指出我正确的方向?
<div ng-app>
<div ng-controller="MainCtrl">
<p> <a href="#" ng-click="Refresh()">Refresh</a> </p>
<p>
<input type="text" ng-model="customer.name">
</p>
<p>{{ customer.name }}</p>
</div>
</div>
function MainCtrl($scope) {
$scope.customer = {
name: 'TTT',
id: 0
};
$scope.Refresh = function ($scope) {
$scope.customer.name = 'Test';
};
}
Run Code Online (Sandbox Code Playgroud)
更新1 08.08.2013 谢谢大家(@EpokK,@ Stewie,@希波克拉底).我现在不明白jsfiddle的问题,这个例子可以正常工作.
但是,在我的测试应用程序中,{{customer.name}}绑定有效,但"刷新"单击仍然不会更改视图中的{{customer.name}}.
这是我的申请内容.我认为它与jsfiddle示例相同:
的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>
Run Code Online (Sandbox Code Playgroud)
app.js
'use strict';
angular.module('roaMobileNgApp', ['ui'])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
});
Run Code Online (Sandbox Code Playgroud)
main.js
'use strict';
angular.module('roaMobileNgApp')
.controller('MainCtrl', function ($scope) {
$scope.customer = {name: '',
id: 0};
$scope.getDetails = function() {
$scope.customer.name = 'Test';
};
});
Run Code Online (Sandbox Code Playgroud)
main.html中
<div ng-controller="MainCtrl">
<a href="#" ng-click="getDetails()">Refresh</a>
<p><input type="text" ng-model="customer.name"> {{ customer.name }} </p>
</div>
Run Code Online (Sandbox Code Playgroud)
只需在小提琴选项中选择“不换行”(因为否则您的演示将无法工作),然后$scope从Refresh函数中删除该参数。您不需要传入,$scope因为函数本身是在 $scope 内定义的。
$scope.getDetails = function(){
$scope.customer.name = 'Test';
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35802 次 |
| 最近记录: |