我的ng-model内部未定义。我已经在我的控制器中定义了。 $scope.rule.message
没问题,但$scope.rule.ruleId
未定义。
html
<form>
<div class="form-group">
<label>Group</label> <select ng-model="rule.ruleId" ng-repeat="rule in rules">
<option value="{{rule.ruleId}}">
#{{rule.keyword}}
</option>
</select>
</div>
<div class="form-group">
<label>Message</label>
<textarea class="form-control" cols="" name="" rows="" ng-model="rule.message">
</textarea>
</div>
<div class="form-group">
<button class="btn btn-default" type="submit" ng-click="create()">Save</button>
</div>
</form>
JS
mzsmsControllers.controller('MemberBlastCreateCtrl', ['$scope', '$http',
'$location',
function($scope, $http, $location) {
$scope.rule = {};
$http({
method: 'GET',
url: 'http://example.com/get_all_rules.php?fbId=' + sessionStorage.id
}).
success(function(data, status, headers, config) {
$scope.rules = data.rules;
}).
error(function(data, status, headers, config) {
alert("No internet connection.");
});
$scope.create = function() {
$http({
method: 'GET',
url: 'http://example.com/create_blast.php?fbId=' + sessionStorage.id +
'&ruleId=' + $scope.rule.ruleId + '&message=' + $scope.rule.message
}).
success(function(data, status, headers, config) {
alert(JSON.stringify(data));
alert("SMS Blast successfuly created.");
$location.path("/member/blast");
}).
error(function(data, status, headers, config) {
alert("No internet connection.");
});
}
}
]);
答案 0 :(得分:1)
我想问题是ng-repeat会创建一个新的范围,尝试更改ng-repeat:
<select ng-model="rule.ruleId" ng-repeat="r in rules">
<option value="{{r.ruleId}}">
#{{r.keyword}}
</option>
</select>