0

I got undefined inside my ng-model. I already defined inside my controller. $scope.rule.message no issue but for $scope.rule.ruleId got undefined.

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.");
            });
        }
    }
]);
3
  • can you print out data.rules? Commented Sep 18, 2014 at 7:29
  • You want multiple selects with a single option? Commented Sep 18, 2014 at 7:32
  • [$scope.rules = data.rules;], [$scope.rules] is called but [$scope.rule] is never called??? Commented Sep 18, 2014 at 7:35

1 Answer 1

1

I guess the problem is that ng-repeat creates a new scope, try changing the ng-repeat:

<select ng-model="rule.ruleId" ng-repeat="r in rules">
        <option value="{{r.ruleId}}">
            #{{r.keyword}}
        </option>
    </select>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.