ng-model不工作AngularJS

时间:2016-08-08 23:56:23

标签: javascript html angularjs data-binding angular-ngmodel

由于某种原因,AngularJS无法在我们的网站上运行..我们对此进行了测试:

register.html:

<form name="register_form">
    <ion-view view-title="Login" align-title="center">
        <ion-content style="background: #FFD700; background-size: cover;">

             <input type="password" ng-model= "name" required="required"/>

            <button ng-click="register_sub()"></button>

        </ion-content>
    </ion-view>
</form>

register.ctrl.js:

(function(angular) {

  'use strict';

    angular
            .module('Hive')
            .controller('registerCtrl', ["$scope", "refService","letterAvatarService", registerCtrlFunc]);

    function registerCtrlFunc($scope, refService,letterAvatarService) {

        $scope.register_sub = function()
        {
              console.log($scope.name)
        }
    }

})(angular);

当我点击按钮时,由于某种原因它会记录Undefined。帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

你的代码很好,除了一个小错误,即。 “ng-model =”和“name”之间有空格

         <input type="password" ng-model= "name" required="required"/>

尝试

         <input type="password" ng-model="name" required="required"/>