亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用ng-include時失去范圍

使用ng-include時失去范圍

使用ng-include時失去范圍我有這個模塊路線: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 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函數$scope.lineText中undefined,這可以通過添加ng-controller="HomeCtrl"來解決partial1.html,但是它會導致控制器被調用兩次。我在這里錯過了什么?
查看完整描述

3 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

這是因為ng-include它創建了一個新的子范圍,因此$scope.lineText不會更改。我認為這this是指當前的范圍,所以this.lineText應該設置。


查看完整回答
反對 回復 2019-07-31
  • 3 回答
  • 0 關注
  • 644 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號