本文将为您提供关于angularjs–为什么ngdocs只读取单个目录而不是多个目录中的js(使用gulp)?的详细介绍,同时,我们还将为您提供关于Angular10:某些目录而不是其他目录的绝对路径
本文将为您提供关于angularjs – 为什么ngdocs只读取单个目录而不是多个目录中的js(使用gulp)?的详细介绍,同时,我们还将为您提供关于Angular 10:某些目录而不是其他目录的绝对路径上出现VScode错误、angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?、angularjs – angular bootstrap typeahead将ng-model设置为对象而不是单个字段、angularjs – 为什么Angular $资源返回一个Resource对象而不是类对象?的实用信息。
本文目录一览:- angularjs – 为什么ngdocs只读取单个目录而不是多个目录中的js(使用gulp)?
- Angular 10:某些目录而不是其他目录的绝对路径上出现VScode错误
- angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?
- angularjs – angular bootstrap typeahead将ng-model设置为对象而不是单个字段
- angularjs – 为什么Angular $资源返回一个Resource对象而不是类对象?
angularjs – 为什么ngdocs只读取单个目录而不是多个目录中的js(使用gulp)?
myapplication/js/controllers/samplecontroller.js myapplication/js/directives/sampledirective.js myapplication/js/main.js myapplication/js/app.js
我的任务是:
gulp.task('ngdocs',[],function () { var gulpDocs = require('gulp-ngdocs'); var options = { scripts: ['./controllers/*.js','./directives/*.js'],startPage: '/api',title: "Awesome Docs",titleLink: "/api" } return gulp.src('myapplication/js/*.js') .pipe(gulpDocs.process(options)) .pipe(gulp.dest('./docs')); });
我注意到生成的文档只是拾取“main.js”和“app.js”中的文档.有没有办法让我在“/ controllers”和“/ directives”下的所有文件都被拾取?或者这不是常见的做法?
解决方法
return gulp.src('myapplication/js/**/*.js')
Angular 10:某些目录而不是其他目录的绝对路径上出现VScode错误
好吧,我已经遇到了这个问题,因此建议您不要使用“ ../../”目录浏览,而不是直接在路径中调用“ src”。
angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?
Router,RouteParams,RouterLink和RouteData似乎没有处理这个问题,例如我想将用户对象从一个状态传递到另一个状态
<a ui-sref="home({user: myCtrl.user})">
这在Angular 2中似乎不可能.
解决方法
<a [routerLink]="['/ProductDetail',{id: 1234}]">Product Details</a>
在这种情况下,id是你的状态,它可以是任何对象,例如:
<a [routerLink]="['/ProductDetail',myStateObject]">Product Details</a>
另一方面,Angular 2有一种机制,可以使用绑定传递参数到组件的@input()参数,但这只能在同一路径中使用.
angularjs – angular bootstrap typeahead将ng-model设置为对象而不是单个字段
例如
mycontroller.js
var getStates = function() { // calls rest service that pulls in states.json from some angular factory } var StateCtrl = function ($scope) { $scope.states = getStates(); $scope.submit = function () { // Should expect an Object and not the name of the state console.log($scope.states); } } angular.module('StateCtrl',[]).controller(['$scope',StateCtrl]);
states.json
[ // i don't want just state.name i want everything {name: Alabama,stateCode: 123,salesTax: .06},{name: Arkansas,stateCode: 122,{name: New York,stateCode: 120,salesTax: .10},... ]
的index.html
<input ng-model="selectedstate" uib-typeahead="state.name for state in states"> <!--- i want selectedState to be {{state}} and not {{state.name}} --> <button ng-click="submit()">submit</button>
angularjs – 为什么Angular $资源返回一个Resource对象而不是类对象?
angular.module('myapp',['ngResource']).factory 'MyObject',['$resource',($resource) -> MyObjectResource = $resource '/api/my_object/:id',{ id: '@id' },{ update: method: 'PUT' } class MyObject extends MyObjectResource someMethod: -> dosomething ]
问题是,当我从API加载一个对象时,我得到一个Resource对象而不是MyObject对象,这是一个问题,因为我无法访问其他方法.
这是我获取对象的代码:
result = MyObject.get({id: 1})
如果我打印结果,我可以看到:
Resource {id: 1,details: 'somestuff'}
相比之下,我希望有:
MyObject {id: 1,details: 'somestuff'}
这将使我能够访问someMethod以及我为此类定义的所有其他方法.
难道我做错了什么?
提前致谢.
解决方法
>在工厂内部创建了一个Resource函数(它是$resource provider),并在调用$resource时返回.
资源具有以下结构(让我们想象一下,我们只想获得它所拥有的方法的高级视图,而不是每个方法的工作方式)
function Resource(value) { ... } Resource.prototype.toJSON = function () { ... } Resource.prototype.bind = function () { ... }
>我还看到$resource函数在第3个参数中接收要在Resource函数上设置的附加动作(与某些默认动作合并),我看到你正在发送一个额外的更新方法,所以对象有以下结构
将更新与默认操作合并:
{ 'get': {method: 'GET'},'save': {method: 'POST'},'query': {method: 'GET',isArray: true},'remove': {method: 'DELETE'},'delete': {method: 'DELETE'},// added by the user update: { method: 'PUT' } }
$resource为Resource函数以及在方法名称之前附加$的Resource的原型设置一个方法,即
Resource.get = function () { ... } Resource.save = function () { ... } Resource.update = function () { ... } ... Resource.prototype.$get = function () { ... } Resource.prototype.$save = function () { ... } Resource.prototype.$update = function () { ... } ...
现在回到你的代码,你从MyObjectResource扩展一个新函数MyObject,其中MyObjectResource是调用$resource的结果,即上面看到的Resource函数,coffeescript的extend实际上将MyObjectResource上定义的所有属性复制到MyObject,并使隐藏[ [Prototype]] MyObject.prototype的属性指向MyObjectResource.prototype:
MyObjectResource prototype -------> MyObjectResource.prototype $get get $save save toJSON ... ... ^ | MyObject | prototype -------> MyObject.prototype get (reference) someMethod set (reference) ...
这就是你可以做MyObject.get的原因,因为它现在有一个对MyObjectResource.get的引用,即MyObject.get === MyObjectResource.get
这是有趣的部分,调用MyObject.get会返回一个MyObjectResrouce的实例(这实际上是被编码的,但只有在MyObject.get内部才会发生,这不是MyObjectResource Source的实例),如果我们做新的MyObjectResource()则无法访问someMethod因为它实际上是在“子类”中定义的.
但是我们可以创建一个MyObject实例,并且由于coffeescript的扩展创建了链接,实例可以通过MyObjectResource.prototype访问相同的内容.$get,所以:
var instance = new MyObject() instance.$get({id: 1}); // works because of the link created between the prototypes instance.someMethod(); // also works
我们今天的关于angularjs – 为什么ngdocs只读取单个目录而不是多个目录中的js(使用gulp)?的分享已经告一段落,感谢您的关注,如果您想了解更多关于Angular 10:某些目录而不是其他目录的绝对路径上出现VScode错误、angularjs – Angular 2中的状态参数(Angular 1&ui-router)的等价物是什么?、angularjs – angular bootstrap typeahead将ng-model设置为对象而不是单个字段、angularjs – 为什么Angular $资源返回一个Resource对象而不是类对象?的相关信息,请在本站查询。
本文标签: