使用 ng-包含时失去作用域
2022-08-30 01:49:50
我有这个模块路由:
var mainModule = angular.module('lpConnect', []).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/home', {template:'views/home.html', controller:HomeCtrl}).
when('/admin', {template:'views/admin.html', controller:AdminCtrl}).
otherwise({redirectTo:'/connect'});
}]);
首页 HTML:
<div ng-include src="views.partial1"></div>
partial1
网页:
<form ng-submit="addLine()">
<input type="text" ng-model="lineText" size="30" placeholder="Type your message here">
</form>
HomeCtrl
:
function HomeCtrl($scope, $location, $window, $http, Common) {
...
$scope.views = {
partial1:"views/partial1.html"
};
$scope.addLine = function () {
$scope.chat.addLine($scope.lineText);
$scope.lines.push({text:$scope.lineText});
$scope.lineText = "";
};
...
}
在函数 is 中,这可以通过添加 来解决,但是它会导致控制器被调用两次。我在这里错过了什么?addLine
$scope.lineText
undefined
ng-controller="HomeCtrl"
partial1.html