0
我遇到問題。我試圖在我的index.html頁面上的html模板頁面上包含一個按鈕。我不喜歡這樣ng-click是ng-included的按鈕
<ng-include src="'logout/logout.template.html'"></ng-include>
的頁面是:
<button type="button" class="btn btn-default btn-sm" ng-click="$ctrl.lala()">
<span class="glyphicon glyphicon-log-out" ></span> Log out
</button>
的問題是,事情不起作用。它不會訪問ctrl功能。在我看來,ng-include與其他角度指令無法正常工作,所以我的問題是,如何在index.html中包含我的按鈕模板而無需粘貼代碼,因爲它連接到組件dservice,所以我可以不會打破它。
的componenent:
'use strict';
angular
.module('logout')
.component('logout', {
templateUrl: 'logout/logout.template.html',
controller: ['$scope', '$location', '$localStorage', 'Logout',
function LogoutController($scope, $location, $localStorage, Logout) {
this.lala = function() {
console.log("doing logout");
}
}
]
});
這是我的理解是'NG-include'創建一個新的子範圍。所以你的函數'lala()'不存在於它被調用的範圍內。 – ksav
你也試過這個嗎? - '
' –@NikhilNanjappa試過了,還沒有工作。 – Mocktheduck