angular.module('app', [])
.controller('mainCtrl', ['$scope', function ($scope) {
$scope.checkVal = function () {
console.log('entered');
console.log($scope.data.user)
}
$scope.data = {
//to keep the data from the api or any static data
//this will used to show the data in the view
user: {
fname: '',
lname: '',
email: '',
password: ''
}
};
$scope.methods = {
//this will called from the views to interact with properties and data
//use methods to change the values
checkVal: function () {
console.log('entered');
console.log($scope.data.user)
},
};
$scope.properties = {
//only to change views for ng-if and ng-show
}
}])
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div action="#" ng-controller="mainCtrl as ctrl">
<div id="modal-login" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form action="#home" ng-submit="ctrl.methods.checkVal()">
<div class="modal-body">
<div class="form-group">
<input ng-model="ctrl.data.user.email" type="text" name="user-email" placeholder="Email:" required>
</div>
<div class="form-group">
<input ng-model="ctrl.data.user.password" type="password" name="password" placeholder="Password:" required>
</div>
</div>
<div class="modal-footer">
<div class="form-group clearfix">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
我正在尝试从表单中插入我在控制器中创建的对象中的值。但不知何故,它并没有这样做。我不明白为什么这个表单的数据绑定不会像我要求的那样在控制台中给出输出。我做错了什么?
HTML
<body>
<div action="#" ng-controller="mainCtrl as ctrl">
<div id="modal-login" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form action="#home" ng-submit="ctrl.methods.checkVal()">
<div class="modal-body">
<div class="form-group">
<input ng-model="ctrl.data.user.email" type="text" name="user-email" placeholder="Email:" required>
</div>
<div class="form-group">
<input ng-model="ctrl.data.user.password" type="password" name="password" placeholder="Password:" required>
</div>
</div>
<div class="modal-footer">
<div class="form-group clearfix">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
JS
angular.module('app', [])
.controller('mainCtrl', ['$scope', function ($scope) {
$scope.checkVal = function () {
console.log('entered');
console.log($scope.data.user)
}
$scope.data = {
//to keep the data from the api or any static data
//this will used to show the data in the view
user: {
fname: '',
lname: '',
email: '',
password: ''
}
};
$scope.methods = {
//this will called from the views to interact with properties and data
//use methods to change the values
checkVal: function () {
console.log('entered');
console.log($scope.data.user)
},
};
$scope.properties = {
//only to change views for ng-if and ng-show
}
}])
答案 0 :(得分:1)
因为您在视图中使用controllerAs必须使用此格式
angular.module('app', [])
.controller('mainCtrl', ['$scope', function ($scope) {
var vm = this;
vm.checkVal = function () {
console.log('entered');
console.log($scope.data.user)
}
vm.data = {
//to keep the data from the api or any static data
//this will used to show the data in the view
user: {
fname: '',
lname: '',
email: '',
password: ''
}
};
vm.methods = {
//this will called from the views to interact with properties and data
//use methods to change the values
checkVal: function () {
console.log('entered');
console.log($scope.data.user)
},
};
vm.properties = {
//only to change views for ng-if and ng-show
}
答案 1 :(得分:0)
试试这个。 JSFiddle
'replaced “ ” with "
Sub CreatePivotTable()
Dim PTCache As PivotCache
Dim PT As PivotTable
Set PTCache = ActiveWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=Range("A1").CurrentRegion)
Worksheets.Add
Set PT = ActiveSheet.PivotTables.Add( _
PivotCache:=PTCache, _
TableDestination:=Range("A3"))
With PT
.PivotFields("Region").Orientation = xlPageField
.PivotFields("Month").Orientation = xlColumnField
.PivotFields("SalesRep").Orientation = xlRowField
.PivotFields("Sales").Orientation = xlDataField
.DisplayFieldCaptions = False
End With
End Sub