Questions tagged «angularjs-ng-include»

4
使用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" }; …

2
除非在$ scope中传递,否则AngularJS ng-include不包括视图
假设ngInclude可以走一条原始道路是错误的吗?我一直试图将我的设置ngInclude如下: <div ng-include src="views/header.html"></div> 这不起作用,但是如果我做这样的事情,它确实起作用。 // HeaderController app.controller('HeaderCtrl', function($scope){ $scope.templates = {[ template: { url: 'views/header.html' } ]}; $scope.template = $scope.templates[0].template; }); 在我的index.html中 <div ng-controller="HeaderCtrl"> <div ng-include src="template.url"></div> </div> 是否ngInclude仅排除超出范围的值?如果是这样,为什么要这样,而不是直接包含html部分。


1
AngularJS:ngInclude vs指令
我不太了解何时使用指令以及何时更适合使用nginclude。以以下示例为例:我有一个局部,password-and-confirm-input-fields.html即用于输入和确认密码的html。我在注册页面和更改密码页面下都使用了它。这两个页面各有一个控制器,部分html没有专用的控制器。 我应该使用指令还是ngInclude为此?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.