我不能在我的控制器中使用$ scope.data,它是未定义的,你能帮忙吗?
由于
contact.html
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"Yes! Welcome to %@",region.identifier);
UILocalNotification* notify = [UILocalNotification new];
notify.alertBody = [NSString stringWithFormat:@"Welcome to %@",region.identifier];
notify.soundName = UILocalNotificationDefaultSoundName;
if (notify.applicationIconBadgeNumber == 0) {
notify.applicationIconBadgeNumber = 1;
}
[[UIApplication sharedApplication] presentLocalNotificationNow:notify];
}
controllers.js
<textarea cols="40" rows="6" name="message" id="message" class="panelInputs" placeholder="Message" ng-model="data.message" ng-change="displayscope()"></textarea>
app.js
angular.module('BoardLine.controllers', ['BoardLine.services'])
.controller('ContactCtrl', function($scope, $stateParams, sessionService, isPhoneGap, isIOS) {
console.log($scope.data);
$scope.displayscope = function() {
console.log("displayscope : ");
console.log($scope.data);
}
})
答案 0 :(得分:4)
您需要首先在控制器中定义属性data
,如$scope.data = {}
。因为ng-model
与data.message
绑定,而data
为undefined
。因此无法分配message
。
答案 1 :(得分:2)
在你的控制器中你应该声明$ scope.date对象
angular.module('BoardLine.controllers', ['BoardLine.services'])
.controller('ContactCtrl', function($scope, $stateParams, sessionService, isPhoneGap, isIOS) {
//add this
$scope.data = {};
console.log($scope.data);
$scope.displayscope = function() {
console.log("displayscope : ");
console.log($scope.data);
}
})