【发布时间】:2018-04-13 06:11:56
【问题描述】:
我想在控制器中执行一个 hello world 函数(通过单击按钮从 html 调用),但我不能调用它,我不知道为什么它不起作用,因为没有任何显示错误。
html代码:
<html ng-app="app">
<div ng-controller="indexController">
<button type="button" ng-click="helloWorld()">action</button>
</div>
和控制器js:
(function () {
'use stritct';
angular
.module('app',[])
.controller('indexController', indexController);
indexController.inject = ['$rootScope','$scope'];
function indexController($rootScope,$scope) {
var vm = this;
vm.helloWorld = helloWorld;
function helloWorld() {
console.log('hello');
}
}
})();
【问题讨论】:
-
您是否尝试过在您的 html 代码中使用 onclick="helloWorld()" 而不是 ng-click="helloWorld()"?
-
指令 ng click 是不是 Angular 的典型特征,是应该使用的指令
标签: javascript angularjs button controller config