我正在使用AngularJS 1.4.2 (带有角材料),并试图实现一个保存函数。但是,ng-click并没有对我的按钮开火。以下是我的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>这是我的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");
}
}]);“内部编辑模型”文本没有输出到控制台。为什么ng-点击不起作用?
发布于 2015-08-03 03:36:04
这是因为您的editModel函数没有附加到$scope。尝试:
$scope.editModel = function(){ ... };https://stackoverflow.com/questions/31779034
复制相似问题