简体   繁体   English

AngularJS ng-click无效

[英]AngularJS ng-click not working

I'm using AngularJS 1.4.2 (with Angular Material) and I'm trying to implement a save function. 我正在使用AngularJS 1.4.2(使用Angular Material),我正在尝试实现一个保存功能。 However, ng-click is not firing on my button. 但是,我的按钮没有触发ng-click。 Here is my HTML code: 这是我的HTML代码:

<div ng-controller="ModelEditController" class="col-lg-12 fontArial slide" ng-repeat="mdl in model">
    <md-content layout-padding>
            <form name="modelEditForm" novalidate role="form" unsaved-warning-form>
            <md-input-container flex style="width:100%">
                        <label>Name</label>
                        <input required name="model_name" ng-model="mdl.model_name" maxlength="100">
                </md-input-container>

        </form>
    </md-content>

    <div class="panel-footer footer" ng-controller="TestController">
        <md-button class="md-fab md-primary md-hue-2" aria-label="Save" ng-click="editModel(mdl)">
                    <md-icon md-svg-src="/img/icons/save.svg"></md-icon>
        </md-button>

    </div>
</div>

And here is my javascript code: 这是我的javascript代码:

var myApp = angular.module('myApp', ['ui.bootstrap', 'ui.router', 'ngCookies', 'ng-sortable', 'vAccordion', 'ngRoute', 'ngAnimate', 'fiestah.money', 'uiSwitch','ngMaterial','ngMessages','unsavedChanges'])
});


myApp.controller('TestController', ['$scope', 'ModelService', function ($scope,ModelService){

        function editModel(xMdl) {
            console.log("Inside edit model");

        }

    }]);

The "Inside edit model" text is not being output to the console. “内部编辑模型”文本未输出到控制台。 Why would the ng-click not be working? 为什么ng-click不起作用?

That's because your editModel function isn't attached to $scope . 那是因为你的editModel函数没有附加到$scope Try: 尝试:

$scope.editModel = function(){ ... };

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM