在AngularJS中传递对象 [英] Passing objects in AngularJS

查看:463
本文介绍了在AngularJS中传递对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI全部,



我不太确定我是否可以在本网站上提出基于角度的问题,如果我不能,那么请为此道歉。



我在我的HTML表单上创建了文本框,用户输入。只需单击一个按钮,我就可以将这些文本框中的文本写入控制台或警报消息中,只要显示此信息,我就不在乎。



HTML代码:



 <   body  >  


< div id =' content' ng-app =' MyApp' ng-controller =' MainController ' >
< label > F名称:< / label >
< input 类型 = text ng-model = FirstName / > < br / >
< label > L Name :: < / label >
& nbsp; < 输入 类型 = text ng-model = 姓氏 / >
& nbsp; & nbsp; < 按钮 ng-click = addNew() > 添加新的< / button >


< / div >

< / body >







主JS文件:



 app.controller(   MainController,function($ scope){

$ scope.FirstName = ;
$ scope.LastName = ;


$ scope.addNew = function(){

console.log(FirstName);
console.log(LastName);


};




});







当我点击按钮时没有任何反应..我有什么遗漏吗?



谢谢

解决方案

scope){


scope.FirstName = ;


scope.LastName = ;

HI All,

I am not so sure if I can ask an angular based question on this website, if I can't, then please I do apologise.

I have created to textboxes on my HTML form that take the users inputs. With a click of a button I would the text in these textboxes to write to console or in an alert message i don't care as long as the this information displays.

HTML CODE:

<body>


    <div id='content' ng-app='MyApp' ng-controller='MainController'>
        <label>F name:</label>
        <input type="text" ng-model="FirstName"/> <br/>
        <label>L Name::</label>
      &nbsp;  <input type="text" ng-model="LastName"/>
     &nbsp; &nbsp;  <button ng-click="addNew()">Add New</button>


    </div>

</body>




Main JS FILE:

app.controller("MainController", function($scope) {

    $scope.FirstName = "";
    $scope.LastName = "";


    $scope.addNew = function() {

        console.log(FirstName);
        console.log(LastName);


    };




});




When I click the button nothing happens.. Is there anything I am missing??

Thank you

解决方案

scope) {


scope.FirstName = "";


scope.LastName = "";


这篇关于在AngularJS中传递对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆