上午嘗試致電角的js的功能,但它說:「無法讀取屬性‘忘記’的未定義」請幫助解決這個呼叫引導功能
我用下面的JS代碼
var rootApp = angular.module('rootApp', ['firstApp','secondApp']);
var firstApp = angular.module('firstApp', []);
firstApp.controller('FirstController', function($scope) {
alert("First app ");
});
var secondApp = angular.module('secondApp', []);
secondApp.controller('SecondController', function($scope) {
alert("Second app. ");
$scope.forget = function() {
alert("forget function calling ");
}
});
和在html中我使用下面的行來調用這個函數。
angular.element(document.getElementById('SecondController')).scope().forget();
我想'SecondController'不是元素的ID,嘗試'angular.element(document.querySelector( '[控制器= 「SecondController」]'))。範圍()。忘記() ;' – Tushar
這是說意外的令牌非法的 – dhaya
我用下面的行,但它仍然說是相同的angular.element(document.querySelector('[controller =「SecondController」]'))scope()。 – dhaya