我是使用UI-Router的新手,我很难让这个控制器正常工作。视图加载,但该功能不会触发ng-click。 JSFiddle
var app = angular.module('app', ['ui.router']);
app.controller('dashboardCtrl', [
'$scope',
function($scope){
$scope.testFunction = function(){
console.log('test');
}
}
]);
app.config(function ($stateProvider, $urlRouterProvider){
$stateProvider.state("dashboard", {
url: "#",
templateUrl: "dashboard.html",
controller: "dashboardCtrl"
});
});
查看
<body ng-app="app">
<nav>
<a ui-sref="dashboard">Dashboard</a>
</nav>
<ui-view></ui-view>
</body>
<script type = "text/ng-template" id = "dashboard.html">
<button ng-click="testfunction()">Click</button>
</script>
答案 0 :(得分:0)
模板中的testfunction
无效,因为控制器中没有名为testfunction
的功能。在控制器中,您将其指定为testFunction
。请注意大写字母&#39; F&#39;在里面。如果你改变它会工作。但是,请注意url: "#"
无效的网址