checkbox insists on being unselected on page load, but I want it to be selected

48 views
Skip to first unread message

Dan Stromberg

unread,
Dec 3, 2024, 5:38:33 PM12/3/24
to Angular and AngularJS discussion

Hi folks.

First off, I'm stuck with AngularJS 1.5.8 for now.  I know, it's terribly old.  It's an internal-only application, and we're actively working on moving off of it.

But for now...

I've tried more variations on this theme than I can count, but so far, none of them have worked.  Below are some of the more representative things I've tried.

If I output my ng-model variable in HTML with {{whatever}}, things look correct.  It's only the checkbox that looks inaccurate, and only on page load.  And if I click the checkbox, it toggles fine.

I've also tried switching from ng-model to ng-checked + ng-click, but it didn't appear to help.

I've also tried setting the ng-model variable with ng-init, but it didn't appear to improve matters.

I'm getting the scope to put it in from a "vm = this;", and then adding variables as vm.whatever as needed.  I half-suspect that my ng-model variable is still undefined when the button is first set up, but no longer undefined when the HTML outputs its value with {{vm.whatever}}.

Any suggestions?  I still consider myself an AngularJS and Javascript newbie.

Thanks!

PS: I'm avoiding combining ng-model with ng-checked, because I heard they don't mix well.

Dan Stromberg

unread,
Dec 4, 2024, 1:41:44 PM12/4/24
to Angular and AngularJS discussion

This turned out to be a CSS issue.

Once I switched to:
    <label style="margin: auto;" ng-class="vm.useDefaultTactTools?'checkbox-label checked':'checkbox-label'">
...things started working.

I have a feeling that isn't normally required.  Can anyone confirm?

Thanks!

Trung Vu

unread,
Dec 4, 2024, 3:59:17 PM12/4/24
to Angular and AngularJS discussion
Do you define controller as vm in your root html or options of component config?

Dan Stromberg

unread,
Dec 4, 2024, 4:35:06 PM12/4/24
to Angular and AngularJS discussion
On Wednesday, December 4, 2024 at 12:59:17 PM UTC-8 trung....@gmail.com wrote:
Do you define controller as vm in your root html or options of component config?

This predates my time in this code, but "vm" is defined like:
function AdminPipelineDeployController($q, $scope, Upload, AppConfig, FlashService, PipelineService, ThemeService) {
    var vm = this;
 

Trung Vu

unread,
Dec 4, 2024, 4:45:03 PM12/4/24
to Angular and AngularJS discussion
that's just using in your js file cant use in view, at your HTML view, u need to define VM like this in your root element:  ng-controller="ExampleController as vm"

Raphael Ayomide Ajibodu

unread,
Dec 5, 2024, 2:04:33 AM12/5/24
to ang...@googlegroups.com
Employ me and let’s work together on this.

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/angular/915e4432-34c7-4f37-9604-09b216af3825n%40googlegroups.com.

Trung Vũ Quang

unread,
Dec 5, 2024, 2:04:33 AM12/5/24
to ang...@googlegroups.com
Do you define controller as vm in your root html or options of component config?

Vào Th 4, 4 thg 12, 2024 lúc 17:18 Dan Stromberg <stro...@gmail.com> đã viết:
--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/angular/915e4432-34c7-4f37-9604-09b216af3825n%40googlegroups.com.
--


Vũ Quang Trung
Software Engineer
Reply all
Reply to author
Forward
0 new messages