Alexander Alexander - 1 year ago 70
AngularJS Question

Can I send value from javascript to angular controller at runtime

For example, I have HTML that will show only in the popup

<div id="popup1" style="display: none; width: 600px; height: 400px; overflow: hidden">
<div ng-controller="DataBindingCtrl">

<div rel="title">
Show or Update Image
<div rel="body" style="padding: 10px; line-height: 150%">
<div >
<img src="" style="float: left; background-color: white; width: 250px; height: 320px; border: 1px solid silver; margin: 5px;"/>
<div class="w2ui-field w2ui-span3">
<form class ="form-horizontal">
<input id="file" style="width: 100px" />{{selBookId}}
<input id="currentRecord" type="text" ng-model="currentRecordText" ng-model-instant>
{{currentRecordText}} {{idRec}}

@*<div rel="buttons">
<button class="btn" onclick="$('#popup2').w2popup()">Switch to Popup 2</button>

I want to set a value for idRec when the user clicks on the popup window button.

Is this possible and what is the proper way ?

Answer Source

I assumed that you want to change the scope variable from jQuery function.

You can use jQuery function in your Angular controller as below.

app.controller('AppCtrl', function($scope) {
    $('.popupCall').on('click', function(){
        $scope.idRec= "newValue";

<button class="btn popupCall">Switch to Popup 2</button>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download