0

I have a bunch of radio groups and a textarea elements that load in a ng-repeat controller. I want to populate all/some of those controls after the controller has finished loading them. I have tried $scope.$on. I have looked at directives, but they are really confusing.

I just want to call a function to populate the form (manipulate DOM) after the controller has finished loading. The controller currently loads (and loads a sub-controller) on the click of a button.

Here's some example code of what I have. The Risks function is what I am calling when the button is clicked.

myApp.controller('spRisks', function ($scope, $http, Service) {
$scope.getRisks = function(){
    var caml = "<View><Query><Where><Eq><FieldRef Name='Owner'/><Value Type='Integer'><UserID/></Value></Eq></Where></Query></View>";
    var ownerData = getDataWithCaml("Owners", caml);
    ownerData.success(function (data) {
        var arrayOfExpressions = [];
        for (var i = 0; i < data.d.results.length; i++){
            arrayOfExpressions.push(CamlBuilder.Expression().LookupMultiField("OwnerTitle").EqualTo(data.d.results[i].Title));
        }
        var newCaml = new CamlBuilder().View().Query().Where()
            .Any(arrayOfExpressions)
            .And()
            .TextField("Control").IsNotNull()
            .ToString();
        newCaml = newCaml.replace(/"/g, '\'');

        var jsonData = getDataWithCaml("Risks", newCaml);
        jsonData.success(function (jsonDataResults) {
            $scope.$apply(function(){$scope.Risks = jsonDataResults.d.results;});
        });
        jQuery('#divQs').show();
    });
    $scope.$on('$viewContentLoaded', function () {
        alert('test');
        Service.getAnswers($('#selYear').val(), $('#selMonth').val());
    });
}

});

Fubak
  • 107
  • 1
  • 11
  • Please read this before proceeding: http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background. And honestly, if you want help, at least do the due diligence of reducing all the irrelevant code and isolate only the issue that you care about. There is no reason whatsover to pollute the question with CAML query when you are asking about radio buttons. Help us help you – New Dev May 04 '15 at 21:59
  • get that jQuery out of there and set scope variables for `ng-show` and use `ng-model` for input values. Your `jQuery('#divQs').show();` is out of sequence but you wouldn't have to wrrry about that if you were using `ng-show` based on a scope boolean variable – charlietfl May 04 '15 at 22:07

0 Answers0