gpt4 book ai didi

javascript - 未添加 AngularJS 类 ng-scope

转载 作者:行者123 更新时间:2023-11-29 16:10:47 27 4
gpt4 key购买 nike

我正在学习 Angular 教程,我在他们的示例中看到 ng-scope 使用指令添加到每个元素。

https://docs.angularjs.org/guide/scope

但我自己的代码没有为每个指令添加ng-scope,从渲染数据来看一切似乎都有效,但出于某种原因,这个 CSS 类是未添加。

我的应用程序是从 Yeoman.io 启动项目开始的,所以我不确定是不是该项目中的某些内容导致了这个问题。

https://github.com/diegonetto/generator-ionic

我将 www 代码作为 .zip 添加到我的保管箱中:

https://www.dropbox.com/s/hn36080isu83vw5/www.zip

教程示例

Tutorial Example

我的例子

My Example

HTML

<h1 style="margin-top: 50px;">Scope Heirachy</h1>

<div class="show-scope-demo">
<div ng-controller="ParentGreetController">
Hello {{name}}!
</div>
<div ng-controller="ChildListController">
<ol>
<li ng-repeat="name in names">{{name}} from {{department}}</li>
</ol>
</div>
</div>

Controller.JS

var moduleTest = angular.module('test', []);


moduleTest
.controller('ParentGreetController', ['$scope', '$rootScope', function ($scope, $rootScope)
{
$scope.name = 'World';
$rootScope.department = 'Angular';
}])

// We will access name which is in both scopes
.controller('ChildListController', ['$scope', function ($scope)
{
$scope.names = ['Igor', 'Misko', 'Vojta'];
}]);

应用.JS

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers', 'invoice1', 'invoice2', 'invoice3', 'test', 'myService'])

.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})

.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider

.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})

.state('app.search', {
url: "/search",
views: {
'menuContent': {
templateUrl: "templates/search.html"
}
}
})

.state('app.browse', {
url: "/browse",
views: {
'menuContent': {
templateUrl: "templates/browse.html"
}
}
})
.state('app.playlists', {
url: "/playlists",
views: {
'menuContent': {
templateUrl: "templates/playlists.html",
controller: 'PlaylistsCtrl'
}
}
})

.state('app.scopeHeirachy', {
url: "/scopeHeirachy",
views: {
'menuContent': {
templateUrl: "templates/sample/scopeHeirachy.html"
}
}
})



;
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/playlists');
});

我尝试使用以下方法打开和关闭 debugInfoEnabled

.config(function($stateProvider, $urlRouterProvider, $compileProvider) {
$compileProvider.debugInfoEnabled(false);

});

.config(function($stateProvider, $urlRouterProvider, $compileProvider) {
$compileProvider.debugInfoEnabled(true);

});

最佳答案

检查您的javascript中是否添加了以下代码行。这通常会删除调试信息,即 Ng-scope。这通常是为了提高生产代码的性能而添加的。

$compileprovider.debuginfoenabled(false)

关于javascript - 未添加 AngularJS 类 ng-scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28688483/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com