HTML 页面中的角度属性可见性
angular property visibility within html page
我有一个简单的角度页面:
<div ng-controller="JoinGameController">
<table>
<tr ng-repeat="game in gameList">
<td>{{game}}</td>
<td> </td>
<td><a href="#!/joinGame" ng-click="selectGame(game)">select</a></td>
</tr>
</table>
<br/>
Selected game: {{selectedGameId}}
<br/>
<a href="#!/joinGame" ng-click="clearSelection()">Clear</a>
<div ng-if="isGameSelected">
<p>To join this game put your name in the box and click the button</p>
<input type="text" ng-model="playerName">
<button ng-click="joinExistingGame()">Join Game</button>
<br/>
<p ng-if="playerAdded">{{addPlayerResponse}}</p>
</div>
</div>
我的问题是播放器输入框:ng-model="playerName">单击按钮时不提供值(绑定不起作用)。但是,当我将其移动到它所属的 DIV 元素上方时,它将起作用。
这是该页面的控制器:
'use strict';
angular.module('pokerApp.joinGame', ['ngRoute'])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/joinGame', {
templateUrl: 'joinGame/joinGame.html',
controller: 'JoinGameController'
});
}])
.controller('JoinGameController', ['$http', '$scope', function ($http, $scope) {
$http.get('http://localhost:8080/PokerGame-REST/allGames').success(function (response) {
$scope.gameList = response;
});
$scope.selectedGameId = null;
$scope.isGameSelected = false;
$scope.playerName = '';
$scope.playerAdded = false;
function selectGame(game) {
$scope.selectedGameId = game;
$scope.isGameSelected = true;
}
function clearSelection() {
$scope.selectedGameId = null;
$scope.isGameSelected = false;
}
function joinExistingGame() {
$http.get('http://localhost:8080/PokerGame-REST/addHand', {
params: {
gameId: $scope.selectedGameId,
name: $scope.playerName
}
}).success(function (response) {
$scope.playerAdded = true;
$scope.addPlayerResponse = response.addHand;
});
}
$scope.selectGame = selectGame;
$scope.clearSelection = clearSelection;
$scope.joinExistingGame = joinExistingGame;
}]);
这里有什么收获?
您的问题是ng-if
创建了子作用域,因此您无法使用div 属性访问ng-if
属性中的属性。
你可以试试$parent.playerName
使用ng-if
指令创建自己的范围的问题。因此playerName
添加到ng-if
指令的这个范围内。
只需在主范围变量中创建,例如:player={}
,然后使用它
<input type="text" ng-model="player.playerName">
相关文章:
- D3在一个调用中绘制不同的SVG形状,没有可见性
- jQuery css可见性在load方法中不起作用
- 页面可见性API实际上支持操作系统屏幕锁定吗
- 有没有一种方法可以从隐藏的可见性(CSS,JS)中获得淡入效果
- JavaScript可见性不起作用('隐藏'起作用,'可见'不起作用)
- 从内部回调的可见性
- Openlayers 3为了可见性而绑定到Vector层的复选框没有任何作用
- 范围属性可见性
- 使用jquery的单个类属性可见性
- css 可见性属性和 javascript setTimeout 方法出错
- 哪个更好?html中元素的可见性属性或显示属性
- 无法获取属性'可见性'的未定义引用或null引用
- 更改可见性属性
- Knockout.js:根据比较的属性确定可见性
- JQuery -输入标签改变可见性属性
- Javascript中的CSS属性可见性问题
- HTML 页面中的角度属性可见性
- CKEDITOR未显示可见性属性的偏差
- 使用 Javascript 更改 CSS 可见性属性
- MapboxGL根据从文件加载的数据的属性设置可见性