简体   繁体   English

如何在角度函数控制器中传递绑定值?

[英]How do I pass a bind value in angular function controller?

I am a newbie in angularjs and needs to pass a model bind value in a function which is declared in controller but when I accesss that value from controller it says undefined. 我是angularjs的新手,需要在控制器中声明的函数中传递模型绑定值,但是当我从控制器访问该值时,它说未定义。 Below is the code 下面是代码

HTML: HTML:

<div>
        <p g-bind-template>{{model.myname}}</p>
        <div>
          <div data-ng-controller="formCtrl" data-ng-init="init(model.myname)"></div>
        </div>
      </div>

In the above HTML when i do {{model.myname}} I can see the value but how to pass it in init method. 在上面的HTML中,当我执行{{model.myname}}时,可以看到该值,但如何在init方法中传递它。

In Controller I have wrote a function 在控制器中,我写了一个函数

$scope.init = function (myname) {
      alert(myname) // displays undefined
    };

Your paragraph tag should be within the ng-controller in html. 您的段落标签应位于html的ng-controller中。 Make it like this: 使它像这样:

<div>    
    <div>
      <div data-ng-controller="formCtrl" data-ng-init="init(model.myname)">
        <p g-bind-template>{{model.myname}}</p>
      </div>
    </div>
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将值传递给Angular JS中的其他控制器 - How do I pass value to different controller in Angular js 我如何发送选择时的下拉值作为参数传递给同一控制器中的另一个函数; 角 - How can I send the dropdown value on selection to pass as a parameter to another function within the same controller; angular 如何将表单控制器名称及其值传递给 Angular 10 中的函数? - How to pass Form controller name and its value to a function in Angular 10? Angular 指令绑定事件并将参数传递给控制器​​函数 - Angular directive bind event and pass parameter to controller function 如何将更改后的隐藏字段值从 ValidateForm JS function 传递到 MVC controller - How do I pass the changed hidden field value from ValidateForm JS function to MVC controller 我如何使用Angular将变量从指令传递给控制器 - How do I pass a variable from directive to a controller using Angular 如何将值传递给 JavaScript 中的 function? - How do I pass a value to a function in JavaScript? 如何在Spring中将值从控制器传递到JSP页面? - How do I pass a value from a controller to a JSP page in Spring? 如何将控制器和动作参数传递给 Rails 3 中的 javascript 函数? - How do I pass the controller and action parameters to a javascript function in Rails 3? 在Angular中,我如何$ eval()一个函数并将元素传递给父函数? - In Angular how do I $eval() a function and pass the element to parent function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM