使用ng-include時(shí)失去范圍我有這個(gè)模塊路線: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'});}]);主頁(yè)HTML:<div ng-include src="views.partial1"></div>partial1 HTML:<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 = "";
};...}在addLine函數(shù)$scope.lineText中undefined,這可以通過(guò)添加ng-controller="HomeCtrl"來(lái)解決partial1.html,但是它會(huì)導(dǎo)致控制器被調(diào)用兩次。我在這里錯(cuò)過(guò)了什么?
使用ng-include時(shí)失去范圍
慕尼黑5688855
2019-07-31 18:14:58