我是Angular 1的初学者,我知道$scope是vew和modal之间的粘合剂. 谁能告诉我这三种定义控制器的方式之间的区别. 1)(function(angular) {'use strict';var myApp = angular.module('myApp', []);myApp.controller('namesCtrl', ['$scope', function($scope) {$scope.customSpice = 'wasabi';}]);})(window.angular);是否使用带有值[‘$scope’,function]的传递数组.仅仅功能还不够吗? 2)angular.module('myApp', []).controller('na...
我目前正在为我的Angular2组件中的模块编写一个测试模块,该模块使用templateUrl属性,因此需要在测试之前进行TestBed.compileComponents异步调用才能进行编译. 我遇到的问题是,promise回调(然后)函数中的所有内容都根本无法运行…好像promise无法解决. 这是我的代码. 模块:import { Component } from "@angular/core";@Component({selector: 'categories-component',templateUrl: '/app/views/catalog/categories/categories-dashb...
我有这个module.ts文件:import { IHttpService, IPromise } from 'angular';export class ProductService {static $inject = ["$http"];constructor(private $http: IHttpService) { }loaded: boolean = false;promise: IPromise<{ data: any }>;getProducts(): IPromise<{ data: any }> {if (!this.loaded) {this.loaded = true;this.promise = this.$http.get('/products.json');}return this.promise;} }var module = angular....
在Angular2应用程序中(使用最终的1.x版本),我有一个带有多个选项卡的页面.父状态/ samples / {id}每个选项卡都有一个子路由.例如. / samples / {id} /位置或/ samples / {id} /执行. 样本数据是服务器API在一个请求中发送的一个大对象,其中包含所有选项卡的数据.所以我只想在激活父路由时(在组件代码或在解析中)加载一次,然后在所有选项卡中从中读取. 有没有一种方法可以直接从父组件到子路由的组件共享对象?有点像范围是在Angula...
我注意到< form>的某些奇怪行为. ng2中的元素,我需要有人向我解释一下:) 我创建了简单的Plunker示例https://plnkr.co/edit/vdrHJBNdd26y6YhPXTHD?p=preview 因此,现在是工作的罚款.如果你输入一些值,然后单击“添加参数”,输入值将在模型进行更新,并保存到输入字段. 但是,如果用< form>包裹< div> ;,像这样的元素https://plnkr.co/edit/vdrHJBNdd26y6YhPXTHD?p=preview和输入不便到现场,然后再次单击“添加参数”,表格将被刷新,你...
我是角2的新手,我尝试过[[ngModel)],如下所示.import { Component } from '@angular/core';@Component({selector: 'my-app',template: `<input [(ngModel)]="model.name" name="name"> <h1>{{model.name}}</h1>` }) export class AppComponent { constructor() { } model = {name: "some value"}; }上面的代码在浏览器中的网页初始加载时产生如下所示的输出.第二个是..import { Component } from '@angular/core';@Component({se...
我有一个离子项目,正在使用以下库:http://gionkunz.github.io/chartist-js/index.html 实际绘制图表是通过以下方式实现的:var chart = new Chartist.Line('.ct-chart', {series: [ {name: 'series-1',data: [{x: new Date(143134652600), y: 53},{x: new Date(143234652600), y: 40},{x: new Date(143340052600), y: 45},{x: new Date(143366652600), y: 40},{x: new Date(143410652600), y: 20},{x: new Date(143508652600), y:...
我正在使用具有polyfills.ts的ugul-cli 1.0.0-beta.16,如下所示:// This file includes polyfills needed by Angular 2 and is loaded before // the app. You can add your own extra polyfills to this file. import 'core-js/es6/symbol'; import 'core-js/es6/object'; import 'core-js/es6/function'; import 'core-js/es6/parse-int'; import 'core-js/es6/parse-float'; import 'core-js/es6/number'; import 'core-js/es6...
我是Angular2世界的新手.为了学习Angular,我遵循了不同的教程,现在我尝试建立一家商店以了解更多信息.但是我马上被困住了. 我正在尝试将此模型引入Angular: 但是我没有成功.我得到不同的错误之类的.TypeError: Cannot read property ‘description’ of undefined and errorTS2322: Type ‘{ … }’ is not assignable to type ‘Product[]’.Type …这是我到目前为止所得到的: 产品类型属性模型export class ProductTypeAttribu...
这个问题已经在这里有了答案: > Can’t get ES6 promise value to display in AngularJS view 1个我在了解角度分量范围时遇到麻烦.如果我做类似的事情:function myComponent(){this.data = 'Hello World'; }let myModule = angular.module('myModule', []);myModule.component('myComponent', {template: `<div>{{$ctrl.data}}</div>`,controller: myComponent });<sc...
如何检测其他组件中的语言变化?我的检测是在标头组件中进行的.我的目标是检测语言变化并设置样式. 子组件:import { TranslateService } from "ng2-translate"; export class ChildComponent{public browserLang: string;constructor(private translate: TranslateService) {this.browserLang = translate.getBrowserLang();} }儿童的HTML:<div ng-class="{black: browserLang == 'en', red: browserLang == 'de'}" >结果是:未添...
我正在尝试使用运行webpack的Laravel Mix将一个角度应用程序编译到一个文件中.我得到错误:Uncaught ReferenceError: app is not defined我的webpack.mix.js:const { mix } = require('laravel-mix');mix.js('resources/assets/js/dependencies.js', 'public/js').sass('resources/assets/sass/app.scss', 'public/css');我的bundle.js://load angular require('angular');//Load Angular's plugins require('angular-ui-router'...
我有些困惑,为什么提取似乎无法正常工作,为什么在这种情况下Angular的$http.get可以正常工作.我的提取请求正在进行中,可以看到我正在创建需要填充一些图像的数组.但这并没有在我的HTML页面上填充任何内容.如果我在延迟一段时间后两次调用该函数,则它似乎确实可以正常工作.如果我将其更改为$http.get,它也可以使用.这是我的提取代码:$scope.getPhotos = (url) => { fetch(url).then(response => {return response.json(); }).then(...
我有一个使用AngularJS的非常简单的datepicker,我想给它一个占位符,以便使用AngularJS转换它(就像我通常在我的项目中一样). 这是我的HTML代码:<div flex class="layout-row"><md-datepicker ng-model="vm.calendarEvent.start" ng-model-options="{ timezone: 'UTC' }" md-placeholder="Une date" translate translate-md-placeholder="PROF.SHARE.DUE"></md-datepicker> </div>这样做会引发此错误:Error: [$compile:multidir] M...
我对Date原型做了一些扩展,例如:interface Date {YearsFromToday(): number; }Date.prototype.YearsFromToday = function (): number {// implementation }我正在使用ionic2教程–v2模板,这是一个非常标准的布局-app.html,app.ts,app.module等. 我想知道是否有一种简单的方法可以在全局范围内进行声明.我不确定将其放在项目的哪个位置?解决方法:将您的猴子补丁代码放入文件中.您可以将其称为Monkey-patch-date.ts,例如: 猴子补...