我有以下HTML:
<li ng-repeat="test in lists.Tests">
<label>
<input type="checkbox" id="cbxAcceptTest" ng-checked="{{test.IsAccepted}}" ng-click="testSelection($event,{{test}})" />
</label>
</li>
和testSelection方法为:
$scope.testSelection = function ($event, test) {
if (test.IsAccepted) {
alert('accept');
}
else {
alert('reject');
}
};
我无法在ngClick上触发此方法,它可以在ngChecked上运行,但是我必须使用ngModel,我已经阅读了以下link中的ngChecked。
答案 0 :(得分:1)
就我而言,我有类似的东西:
<li ng-repeat="item in items">
<label>
<input type="checkbox" ng-model="item.auto" ng-click="onAutoClick(item)" />
</label>
</li>
在我的控制器中:
$scope.onAutoClick = function(item) {
if(item.auto){
// checked (true condition)
} else {
// unchecked ( false condition)
}
};
答案 1 :(得分:1)
当您将其作为参数传递时,只需删除测试周围的花括号即可。
答案 2 :(得分:1)
请检查Plnkr。
在HTML中,您需要删除花括号
//Settings.h
@interface Settings : NSObject
+ (Settings *)sharedSettings;
@property(nonatomic, strong) UIColor *themeColor
@end
//Settings.m
+(Settings *)sharedSettings {
static Settings *sharedSettings = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedSettings = [[self alloc] init];
});
return sharedSettings;
}
- (instancetype)init {
if(self = [super init]) {
UIColor *savedColor = [[NSUserDefaults standardUserDefaults] objectForKey:@"ThemeColor"];
if(savedColor) {
self.themeColor = savedColor;
} else {
self.themeColor = defaultColor; //Ex:[UIColor whiteColor];
}
}
return self;
}
- (void)colorChanged:(UIColor *)color {
[[NSUserDefaults standardUserDefaults] setObject:color forKey:@"ThemeColor"];
[[NSUserDefaults standardUserDefaults] synchronize];
}